Add emoji capability to bot

This commit is contained in:
Jeremy Zhang 2017-05-29 22:07:32 +00:00
parent edfcb63706
commit f25669e1bc
3 changed files with 24 additions and 1 deletions

View File

@ -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)

View File

@ -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 = []

View File

@ -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