2017-08-20 21:56:54 +02:00
|
|
|
import socketio
|
2018-07-16 05:50:31 +02:00
|
|
|
from titanembeds.utils import get_message_author, get_message_mentions, get_roles_list, get_attachments_list, get_embeds_list, get_formatted_message, get_formatted_user, get_formatted_emojis, get_formatted_guild, get_formatted_channel, get_formatted_role
|
2018-03-23 00:07:52 +01:00
|
|
|
import discord
|
2017-08-20 21:56:54 +02:00
|
|
|
|
|
|
|
class SocketIOInterface:
|
|
|
|
def __init__(self, bot, redis_uri):
|
|
|
|
self.io = socketio.AsyncRedisManager(redis_uri, write_only=True, channel='flask-socketio')
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
async def on_message(self, message):
|
2018-03-22 23:55:09 +01:00
|
|
|
if message.guild:
|
2018-07-16 05:50:31 +02:00
|
|
|
msg = get_formatted_message(message)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('MESSAGE_CREATE', data=msg, room=str("CHANNEL_"+str(message.channel.id)), namespace='/gateway')
|
2017-08-22 08:57:30 +02:00
|
|
|
|
|
|
|
async def on_message_delete(self, message):
|
2018-03-22 23:55:09 +01:00
|
|
|
if message.guild:
|
2018-07-16 05:50:31 +02:00
|
|
|
msg = get_formatted_message(message)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('MESSAGE_DELETE', data=msg, room=str("CHANNEL_"+str(message.channel.id)), namespace='/gateway')
|
2017-08-22 08:57:30 +02:00
|
|
|
|
|
|
|
async def on_message_update(self, message):
|
2018-03-22 23:55:09 +01:00
|
|
|
if message.guild:
|
2018-07-16 05:50:31 +02:00
|
|
|
msg = get_formatted_message(message)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('MESSAGE_UPDATE', data=msg, room=str("CHANNEL_"+str(message.channel.id)), namespace='/gateway')
|
2017-08-22 08:57:30 +02:00
|
|
|
|
|
|
|
async def on_guild_member_add(self, member):
|
2018-07-16 05:50:31 +02:00
|
|
|
user = get_formatted_user(member)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_MEMBER_ADD', data=user, room=str("GUILD_"+str(member.guild.id)), namespace='/gateway')
|
2017-08-22 08:57:30 +02:00
|
|
|
|
|
|
|
async def on_guild_member_remove(self, member):
|
2018-07-16 05:50:31 +02:00
|
|
|
user = get_formatted_user(member)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_MEMBER_REMOVE', data=user, room=str("GUILD_"+str(member.guild.id)), namespace='/gateway')
|
2017-08-22 08:57:30 +02:00
|
|
|
|
|
|
|
async def on_guild_member_update(self, member):
|
2018-07-16 05:50:31 +02:00
|
|
|
user = get_formatted_user(member)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_MEMBER_UPDATE', data=user, room=str("GUILD_"+str(member.guild.id)), namespace='/gateway')
|
2017-08-22 09:53:41 +02:00
|
|
|
|
|
|
|
async def on_guild_emojis_update(self, emojis):
|
2018-07-16 05:50:31 +02:00
|
|
|
emotes = get_formatted_emojis(emojis)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_EMOJIS_UPDATE', data=emotes, room=str("GUILD_"+str(emojis[0].guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_guild_update(self, guild):
|
2018-07-16 05:50:31 +02:00
|
|
|
guildobj = get_formatted_guild(guild)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_UPDATE', data=guildobj, room=str("GUILD_"+str(guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_channel_delete(self, channel):
|
|
|
|
if str(channel.type) != "text":
|
|
|
|
return
|
2018-07-16 05:50:31 +02:00
|
|
|
chan = get_formatted_channel(channel)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('CHANNEL_DELETE', data=chan, room=str("GUILD_"+str(channel.guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_channel_create(self, channel):
|
|
|
|
if str(channel.type) != "text":
|
|
|
|
return
|
2018-07-16 05:50:31 +02:00
|
|
|
chan = get_formatted_channel(channel)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('CHANNEL_CREATE', data=chan, room=str("GUILD_"+str(channel.guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_channel_update(self, channel):
|
2018-03-23 00:07:52 +01:00
|
|
|
if not isinstance(channel, discord.channel.TextChannel) and not isinstance(channel, discord.channel.CategoryChannel):
|
2017-08-25 08:37:14 +02:00
|
|
|
return
|
2018-07-16 05:50:31 +02:00
|
|
|
chan = get_formatted_channel(channel)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('CHANNEL_UPDATE', data=chan, room=str("GUILD_"+str(channel.guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_guild_role_create(self, role):
|
2018-07-16 05:50:31 +02:00
|
|
|
rol = get_formatted_role(role)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_ROLE_CREATE', data=rol, room=str("GUILD_"+str(role.guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_guild_role_update(self, role):
|
2018-07-16 05:50:31 +02:00
|
|
|
rol = get_formatted_role(role)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_ROLE_UPDATE', data=rol, room=str("GUILD_"+str(role.guild.id)), namespace='/gateway')
|
2017-08-25 08:37:14 +02:00
|
|
|
|
|
|
|
async def on_guild_role_delete(self, role):
|
2018-07-16 05:50:31 +02:00
|
|
|
rol = get_formatted_role(role)
|
2018-03-22 23:55:09 +01:00
|
|
|
await self.io.emit('GUILD_ROLE_DELETE', data=rol, room=str("GUILD_"+str(role.guild.id)), namespace='/gateway')
|