From f25669e1bc018965b135f627633830e58ae001e9 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 29 May 2017 22:07:32 +0000 Subject: [PATCH] Add emoji capability to bot --- discordbot/titanembeds/bot.py | 6 ++++++ discordbot/titanembeds/database/__init__.py | 15 +++++++++++++++ discordbot/titanembeds/database/guilds.py | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py index c6346b9..238842c 100644 --- a/discordbot/titanembeds/bot.py +++ b/discordbot/titanembeds/bot.py @@ -161,3 +161,9 @@ class Titan(discord.Client): async def on_member_unban(self, server, user): await self.database.unban_server_user(user, server) + + async def on_server_emojis_update(self, before, after): + if len(after) == 0: + await self.database.update_guild(before[0].server) + else: + await self.database.update_guild(after[0].server) diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index bd63774..cd53bcd 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -126,6 +126,7 @@ class DatabaseInterface(object): guild.name, json.dumps(self.get_roles_list(guild.roles)), json.dumps(self.get_channels_list(guild.channels)), + json.dumps(self.get_emojis_list(guild.emojis)), guild.owner_id, guild.icon ) @@ -134,9 +135,23 @@ class DatabaseInterface(object): gui.name = guild.name gui.roles = json.dumps(self.get_roles_list(guild.roles)) gui.channels = json.dumps(self.get_channels_list(guild.channels)) + gui.emojis = json.dumps(self.get_emojis_list(guild.emojis)) gui.owner_id = guild.owner_id gui.icon = guild.icon session.commit() + + def get_emojis_list(self, guildemojis): + emojis = [] + for emote in guildemojis: + emojis.append({ + "id": emote.id, + "name": emote.name, + "require_colons": emote.require_colons, + "managed": emote.managed, + "roles": self.list_role_ids(emote.roles), + "url": emote.url + }) + return emojis def get_roles_list(self, guildroles): roles = [] diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py index 4bae06a..ee647cf 100644 --- a/discordbot/titanembeds/database/guilds.py +++ b/discordbot/titanembeds/database/guilds.py @@ -11,10 +11,11 @@ class Guilds(Base): mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg roles = db.Column(db.Text()) # Guild Roles channels = db.Column(db.Text()) # Guild channels + emojis = db.Column(db.Text()) # Guild Emojis owner_id = db.Column(db.String(255)) # Snowflake of the owner icon = db.Column(db.String(255)) # The icon string, null if none - def __init__(self, guild_id, name, roles, channels, owner_id, icon): + def __init__(self, guild_id, name, roles, channels, emojis, owner_id, icon): self.guild_id = guild_id self.name = name self.unauth_users = True # defaults to true @@ -23,6 +24,7 @@ class Guilds(Base): self.mentions_limit = -1 # -1 = unlimited mentions self.roles = roles self.channels = channels + self.emojis = emojis self.owner_id = owner_id self.icon = icon