forked from viveksantayana/geas-bot
Updated documentation.
Changed virtual environment settings. Beginning change to data structure.
This commit is contained in:
42
app/bot.py
42
app/bot.py
@ -23,13 +23,13 @@ def yaml_dump(data:dict, filepath:str):
|
||||
yaml.dump(data, file)
|
||||
|
||||
# Locate or create config file
|
||||
configFile = './data/config.yml'
|
||||
configFile = os.getenv('CONFIG') if os.getenv('CONFIG').endswith('.yml') else './data/config.yml'
|
||||
|
||||
if not os.path.exists(configFile):
|
||||
yaml_dump({},configFile)
|
||||
|
||||
# Locate or create data file
|
||||
dataFile = './data/data.yml'
|
||||
dataFile = os.getenv('DATA') if os.getenv('DATA').endswith('.yml') else './data/data.yml'
|
||||
|
||||
if not os.path.exists(dataFile):
|
||||
yaml_dump({},dataFile)
|
||||
@ -63,7 +63,6 @@ slash = SlashCommand(
|
||||
# sync_on_reload is an important parameter that will become relevant when having to reload cogs on changing bot configs.
|
||||
|
||||
# Define Config keys
|
||||
configKeys = ['adminroles', 'committeerole', 'botrole', 'modchannel', 'name', 'owner', 'prefix']
|
||||
|
||||
def setConfig(guild:discord.Guild):
|
||||
#### Check if the bot is missing any config entries for the guilds it is in, and if it is then add it in.
|
||||
@ -71,29 +70,34 @@ def setConfig(guild:discord.Guild):
|
||||
#### Because the bot connects to Discord after it loads, it will not be able to introspect and see what guilds it is part of before the commands are first loaded, and it will only add new guilds to the config files after it has already connected.
|
||||
#### The Bot will first need to set up all of its configurations, and then begin loading all other commands once it is ready.
|
||||
conf = yaml_load(configFile)
|
||||
if str(guild.id) not in conf:
|
||||
conf[str(guild.id)] = {}
|
||||
if 'name' not in conf[str(guild.id)] or conf[str(guild.id)]['name'] != guild.name:
|
||||
conf[str(guild.id)]['name'] = guild.name
|
||||
if 'owner' not in conf[str(guild.id)] or conf[str(guild.id)]['owner'] != guild.owner_id:
|
||||
conf[str(guild.id)]['owner'] = guild.owner_id
|
||||
if 'adminroles' not in conf[str(guild.id)] or (type(conf[str(guild.id)]['adminroles']) is not list or len(conf[str(guild.id)]['adminroles']) == 0 or None in conf[str(guild.id)]['adminroles']):
|
||||
conf[str(guild.id)]['adminroles'] = []
|
||||
for role in guild.roles:
|
||||
if not (role.is_bot_managed() or role.is_integration()) and role.permissions.administrator:
|
||||
conf[str(guild.id)]['adminroles'].append(role.id)
|
||||
if 'prefix' not in conf[str(guild.id)]:
|
||||
conf[str(guild.id)]['prefix'] = '-'
|
||||
if 'modchannel' not in conf[str(guild.id)]:
|
||||
guildStr = str(guild.id)
|
||||
if guildStr not in conf:
|
||||
conf[guildStr] = {}
|
||||
if 'name' not in conf[guildStr] or conf[guildStr]['name'] != guild.name:
|
||||
conf[guildStr]['name'] = guild.name
|
||||
if 'configured' not in conf[guildStr] or conf[guildStr]['configured'] is not bool:
|
||||
conf[guildStr]['configured'] = False
|
||||
if 'owner' not in conf[guildStr] or conf[guildStr]['owner'] != guild.owner_id:
|
||||
conf[guildStr]['owner'] = guild.owner_id
|
||||
if 'roles' not in conf[guildStr] or (type(conf[guildStr])['roles'] is not dict or len(conf[guildStr]['roles']) == 0 or None in conf[guildStr]['roles']):
|
||||
conf[guildStr]['roles'] = {}
|
||||
if 'admin' not in conf[guildStr]['roles'] or (type(conf[guildStr]['roles']['admin']) is not list or len(conf[guildStr]['roles']['admin']) == 0 or None in conf[guildStr]['roles']['admin']):
|
||||
conf[guildStr]['roles']['admin'] = []
|
||||
for role in guild.roles:
|
||||
if not (role.is_bot_managed() or role.is_integration()) and role.permissions.administrator:
|
||||
conf[guildStr]['roles']['admin'].append(role.id)
|
||||
if 'prefix' not in conf[guildStr]:
|
||||
conf[guildStr]['prefix'] = '-'
|
||||
if 'modchannel' not in conf[guildStr]:
|
||||
if guild.system_channel is None:
|
||||
p = len(guild.channels)
|
||||
c = None
|
||||
for t in guild.text_channels:
|
||||
if t.position < p:
|
||||
p = t.position
|
||||
conf[str(guild.id)]['modchannel'] = t.id
|
||||
conf[guildStr]['modchannel'] = t.id
|
||||
else:
|
||||
conf[str(guild.id)]['modchannel'] = guild.system_channel.id
|
||||
conf[guildStr]['modchannel'] = guild.system_channel.id
|
||||
yaml_dump(conf, configFile)
|
||||
|
||||
def clearConfig(guildKey:str):
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user