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

Commit

Permalink
servers not added
Browse files Browse the repository at this point in the history
  • Loading branch information
jgayfer committed Aug 30, 2017
1 parent 604d1c9 commit d1e8739
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cogs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ async def on_ready(self):
print('Username: {}'.format(self.bot.user.name))
print('------')

# Get guilds in database
with DBase() as db:
db = db.get_guilds()
db_guilds = []
to_delete = []
for row in db:
guild = self.bot.get_guild(row[0])
if guild:
db_guilds.append(guild)
else:
to_delete.append(row[0])

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

# Remove guilds
for guild_id in to_delete:
with DBase() as db:
db.remove_guild(guild_id)


async def on_guild_join(self, guild):
"""Add guild and it's members to database"""
Expand Down
12 changes: 10 additions & 2 deletions db/dbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ def delete_event(self, guild_id, title):
def add_guild(self, guild_id):
sql = """
INSERT INTO guilds (guild_id)
VALUES (%s);
VALUES (%s)
ON DUPLICATE KEY UPDATE guild_id = %s;
"""
self.cur.execute(sql, (guild_id,))
self.cur.execute(sql, (guild_id, guild_id))
self.conn.commit()

def remove_guild(self, guild_id):
Expand All @@ -147,6 +148,13 @@ def remove_guild(self, guild_id):
self.cur.execute(sql, (guild_id,))
self.conn.commit()

def get_guilds(self):
sql = """
SELECT * FROM guilds;
"""
self.cur.execute(sql)
return self.cur.fetchall()

def add_user(self, username):
sql = """
INSERT INTO users (username)
Expand Down

0 comments on commit d1e8739

Please sign in to comment.