Added productivity feature

This commit is contained in:
2023-11-19 13:47:16 +01:00
parent bea5e393c6
commit 23c4047bf7
7 changed files with 254 additions and 83 deletions

View File

@@ -1,5 +1,7 @@
import discord
from ..cogs.birthday import BirthdayCog
from ..cogs.productivity import ProductivityCog
from .logger import LOGGER
bot_intents = discord.Intents.default()
bot_intents.message_content = True
@@ -10,4 +12,15 @@ bot_intents.reactions = True
bot = discord.Bot(command_prefix='$', intents=bot_intents)
bot.add_cog(BirthdayCog(bot))
COGS = [BirthdayCog, ProductivityCog]
for cog in COGS:
bot.add_cog(cog(bot))
def reload_feature(feature:str):
LOGGER.debug(bot.cogs)
LOGGER.debug(f'Reloading {feature}...')
bot.remove_cog(feature.capitalize()+'Cog')
cog = globals()[feature.capitalize()+'Cog']
bot.add_cog(cog(bot))
LOGGER.debug(f'{feature} reloaded!')

View File

@@ -1,4 +1,7 @@
import os, json
from .logger import LOGGER
FEATURES = ['birthday','productivity']
DATA_DIR = 'data/'
@@ -12,4 +15,25 @@ def save_guild_data(guild_id:int, data):
"""Saves the dictionary of guild data to the guild's JSON data file."""
path = os.path.join(DATA_DIR, f'{guild_id}.json')
with open(path, 'w') as f:
json.dump(data, f, indent=2)
json.dump(data, f, indent=2)
LOGGER.debug(f'Saved data file for guild {guild_id}.')
def create_guild_data(guild_id:int):
"""Creates a new guild data file."""
path = os.path.join(DATA_DIR, f'{guild_id}.json')
with open(path,'w') as f:
json.dump({'features': {key:{'enabled':True} for key in FEATURES}}, f, indent=2)
LOGGER.debug(f'Created data file for guild {guild_id}.')
def delete_guild_data(guild_id:int):
"""Deletes the guild data file."""
path = os.path.join(DATA_DIR, f'{guild_id}.json')
os.remove(path)
LOGGER.debug(f'Deleted data file for guild {guild_id}.')
def is_feature_enabled(feature:str,data=None,guild_id=0):
"""Returns True if the feature is enabled in the guild, False otherwise."""
if data:
return data['features'][feature]['enabled']
else:
return get_guild_data(guild_id)['features'][feature]['enabled']

View File

@@ -3,6 +3,6 @@ import logging
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(asctime)s: %(name)s: %(message)s')
LOGGER = logging.getLogger('botmafieux')
LOGGER.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='botmafieux.log', encoding='utf-8', mode='w')
handler = logging.FileHandler(filename='botmafieux.log', encoding='utf-8', mode='a')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
LOGGER.addHandler(handler)