Skip to content

Commit

Permalink
Switch logs to its own collection (Modmail v2.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Jan 18, 2019
1 parent 426506c commit 3db9faa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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.6.0

Mostly internal changes. Some are slightly breaking. Keep a lookout for broken features and report them on our server.

### Added
- `threads` is now a default alias to `logs`

### Changed
- Log URLs are moved to their own collection.
- Log URLs are now `https://logs.modmail.tk/LOGKEY`, no more numbers before the logkey.
- We still support the numbers so as to not break everyone's urls so quickly but both work atm :p
- This is a huge change to the backend logging and there might be migration errors. If so, please contact us at our [discord server](https://discord.gg/2fMbf2N)

# v2.5.2

Non-Breaking Internal Changes. (This shouldn't affect anyone.)
Expand Down
9 changes: 4 additions & 5 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Modmail:

def __init__(self, bot):
self.bot = bot

def obj(arg):
return discord.Object(int(arg))

Expand Down Expand Up @@ -299,7 +299,7 @@ async def nsfw(self, ctx):
await ctx.channel.edit(nsfw=True)
await ctx.message.add_reaction('✅')

@commands.command()
@commands.command(aliases=['threads'])
@commands.has_permissions(manage_messages=True)
@trigger_typing
async def logs(self, ctx, *, member: Union[discord.Member, discord.User, obj]=None):
Expand Down Expand Up @@ -342,10 +342,9 @@ async def logs(self, ctx, *, member: Union[discord.Member, discord.User, obj]=No
new_day = date.strftime(r'%d %b %Y')
time = date.strftime(r'%H:%M')

key = entry['key']
user_id = entry.get('user_id')
key = entry['_id']
closer = entry['closer']['name']
log_url = f"https://logs.modmail.tk/{user_id}/{key}" if not self.bot.selfhosted else self.bot.config.log_url + f'/logs/{key}'
log_url = f"https://logs.modmail.tk/{key}" if not self.bot.selfhosted else self.bot.config.log_url + f'/logs/{key}'

truncate = lambda c: c[:47].strip() + '...' if len(c) > 50 else c

Expand Down
1 change: 0 additions & 1 deletion core/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ async def from_repo(cls, bot, url=None):
if __name__ == '__main__':
with open('../CHANGELOG.md') as f:
changelog = ChangeLog(f.read())
print(changelog.latest_version)
11 changes: 5 additions & 6 deletions core/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def login(cls, bot):

class ModmailApiClient(ApiClient):

base = 'https://api.modmail.tk'
base = 'http://api.example.com'
metadata = base + '/metadata'
github = base + '/github'
logs = base + '/logs'
Expand Down Expand Up @@ -205,7 +205,6 @@ async def get_user_logs(self, user_id):
async def get_log(self, channel_id):
return await self.logs.find_one({'channel_id': str(channel_id)})


async def get_log_url(self, recipient, channel, creator):
key = secrets.token_hex(6)

Expand All @@ -232,17 +231,17 @@ async def get_log_url(self, recipient, channel, creator):
},
'closer': None,
'messages': []
})
})

return f'{self.app.config.log_url}/logs/{key}'

async def get_config(self):
conf = await self.db.config.find_one({'bot_id': self.app.user.id})
if conf is None:
await self.db.config.insert_one({'bot_id': self.app.user.id})
return {'bot_id': self.app.user.id}
return conf

async def update_config(self, data):
valid_keys = self.app.config.valid_keys - self.app.config.protected_keys
data = {k: v for k, v in data.items() if k in valid_keys}
Expand Down
6 changes: 3 additions & 3 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ async def _close(self, closer, silent=False, delete_channel=True,
return

if self.bot.selfhosted:
log_url = f'{self.bot.config.log_url}/logs/{log_data["key"]}'
log_url = f'{self.bot.config.log_url}/logs/{log_data["_id"]}'
else:
log_url = f"https://logs.modmail.tk/" \
f"{log_data['user_id']}/{log_data['key']}"
f"{log_data['_id']}"

user = self.recipient.mention if self.recipient else f'`{self.id}`'

Expand All @@ -116,7 +116,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
else:
sneak_peak = 'No content'

desc = f"{user} [`{log_data['key']}`]({log_url}): {sneak_peak}"
desc = f"{user} [`{log_data['_id']}`]({log_url}): {sneak_peak}"

em = discord.Embed(description=desc, color=discord.Color.red())

Expand Down

0 comments on commit 3db9faa

Please sign in to comment.