Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
cleanup guild add/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jgayfer committed Sep 25, 2017
1 parent a8358da commit cd39d73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
19 changes: 1 addition & 18 deletions cogs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,14 @@ async def on_ready(self):
for row in results:
guild_id = row.get('guild_id')
guild = self.bot.get_guild(guild_id)
if guild:
db_guilds.append(guild)
else:
if not guild:
to_delete.append(guild_id)

# Add guilds
for guild in self.bot.guilds:
if guild not in db_guilds:
self.bot.db.add_guild(guild.id)

# Remove guilds
for guild_id in to_delete:
self.bot.db.remove_guild(guild_id)


async def on_guild_join(self, guild):
"""Add guild and it's members to database"""
self.bot.db.add_guild(guild.id)


async def on_guild_remove(self, guild):
"""Remove guild from database"""
self.bot.db.remove_guild(guild.id)


async def on_member_remove(self, user):
"""Remove user from database when they leave the guild"""
member_ids = []
Expand Down
9 changes: 5 additions & 4 deletions spirit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async def _prefix_callable(bot, message):
if result:
base.append(result.get('prefix'))
else:
raise ValueError('Could not fetch prefix from database')
bot.db.add_guild(message.guild.id)
base.append('!')
return base


Expand All @@ -48,9 +49,9 @@ def run(self):
if __name__ == '__main__':

with open('credentials.json') as f:
token = json.load(f)['token']
with open('credentials.json') as f:
api_key = json.load(f)['d2-api-key']
file_dict = json.load(f)
token = file_dict['token']
api_key = file_dict['d2-api-key']

destiny = pydest.Pydest(api_key)
bot = Spirit(token)
Expand Down

0 comments on commit cd39d73

Please sign in to comment.