Fix emoji tuples out of range and no permission to read message issues

This commit is contained in:
Jeremy Zhang 2018-12-30 20:22:58 +00:00
parent 5239c2ffc0
commit 4f27dedd6f
2 changed files with 26 additions and 14 deletions

View File

@ -178,11 +178,10 @@ class Titan(discord.AutoShardedClient):
await self.redisqueue.ban_member(guild, user)
async def on_guild_emojis_update(self, guild, before, after):
await self.redisqueue.update_guild(guild)
if len(after) == 0:
await self.redisqueue.update_guild(guild)
await self.socketio.on_guild_emojis_update(before)
else:
await self.redisqueue.update_guild(guild)
elif len(before) == 0:
await self.socketio.on_guild_emojis_update(after)
async def on_webhooks_update(self, channel):
@ -193,6 +192,8 @@ class Titan(discord.AutoShardedClient):
data = payload.data
if not self.in_messages_cache(int(message_id)):
channel = self.get_channel(int(data["channel_id"]))
me = channel.guild.get_member(self.user.id)
if channel.permissions_for(me).read_messages:
message = await channel.get_message(int(message_id))
await self.on_message_edit(None, message)
@ -225,6 +226,8 @@ class Titan(discord.AutoShardedClient):
message_id = payload.message_id
if not self.in_messages_cache(message_id):
channel = self.get_channel(payload.channel_id)
me = channel.guild.get_member(self.user.id)
if channel.permissions_for(me).read_messages:
message = await channel.get_message(message_id)
await self.on_reaction_add(message.reactions[0], None)
@ -234,6 +237,8 @@ class Titan(discord.AutoShardedClient):
partial = payload.emoji
emoji = self._connection._upgrade_partial_emoji(partial)
channel = self.get_channel(payload.channel_id)
me = channel.guild.get_member(self.user.id)
if channel.permissions_for(me).read_messages:
message = await channel.get_message(message_id)
message._add_reaction({"me": payload.user_id == self.user.id}, emoji, payload.user_id)
reaction = message._remove_reaction({}, emoji, payload.user_id)
@ -243,6 +248,8 @@ class Titan(discord.AutoShardedClient):
message_id = payload.message_id
if not self.in_messages_cache(message_id):
channel = self.get_channel(payload.channel_id)
me = channel.guild.get_member(self.user.id)
if channel.permissions_for(me).read_messages:
message = await channel.get_message(message_id)
await self.on_reaction_clear(message, [])

View File

@ -121,7 +121,12 @@ class RedisQueue:
await self.push_message(message)
async def on_get_guild_member(self, key, params):
member = self.bot.get_guild(int(params["guild_id"])).get_member(int(params["user_id"]))
guild = self.bot.get_guild(int(params["guild_id"]))
if not guild:
await self.connection.set(key, "")
await self.enforce_expiring_key(key)
return
member = guild.get_member(int(params["user_id"]))
if not member:
await self.connection.set(key, "")
await self.enforce_expiring_key(key)