Skip to content

Commit

Permalink
Fixed a one off bug for Raring
Browse files Browse the repository at this point in the history
  • Loading branch information
kyb3r committed Jan 5, 2019
1 parent a0249f5 commit d3ac723
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

#v2.0.4

### Fixed
- Fixed a one off bug where the channel topic dissapears, but modmail operations should still continue
- Fixed linked_message_id issues.

# v2.0.3

Fixed some issues with how data is displayed in the info embed.
Expand Down
10 changes: 7 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""

__version__ = '2.0.3'
__version__ = '2.0.4'

import asyncio
import textwrap
Expand Down Expand Up @@ -120,10 +120,14 @@ def modmail_guild(self):
return self.guild
else:
return discord.utils.get(self.guilds, id=int(modmail_guild_id))

@property
def using_multiple_server_setup(self):
return self.modmail_guild != self.guild

@property
def main_category(self):
if self.guild:
if self.modmail_guild:
return discord.utils.get(self.modmail_guild.categories, name='Mod Mail')

@property
Expand Down Expand Up @@ -245,7 +249,7 @@ async def on_message_delete(self, message):
"""Support for deleting linked messages"""
if message.embeds and not isinstance(message.channel, discord.DMChannel):
message_id = str(message.embeds[0].author.url).split('/')[-1]
if matches:
if message_id.isdigit():
thread = await self.threads.find(channel=message.channel)

channel = thread.recipient.dm_channel
Expand Down
21 changes: 12 additions & 9 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ def __init__(self, bot):

async def populate_cache(self):
for channel in self.bot.modmail_guild.text_channels:
if not self.bot.using_multiple_server_setup and channel.category != self.main_category:
continue
await self.find(channel=channel)


def __len__(self):
return len(self.cache)

Expand Down Expand Up @@ -177,15 +180,15 @@ async def _find_from_channel(self, channel):
if channel.topic and 'User ID: ' in channel.topic:
user_id = int(re.findall(r'\d+', channel.topic)[0])

# BUG: This wont work with multiple categories.
# elif channel.topic is None:
# async for message in channel.history(limit=50):
# if message.embeds:
# em = message.embeds[0]
# matches = re.findall(r'<@(\d+)>', str(em.description))
# if matches:
# user_id = int(matches[-1])
# break
# BUG: When discord fails to create channel topic. search through message history
elif channel.topic is None:
async for message in channel.history(limit=50):
if message.embeds:
em = message.embeds[0]
matches = re.findall(r'User ID: (\d+)', str(em.footer.text))
if matches:
user_id = int(matches[0])
break

if user_id is not None:
if user_id in self.cache:
Expand Down

0 comments on commit d3ac723

Please sign in to comment.