Skip to content

Commit

Permalink
Added log link command
Browse files Browse the repository at this point in the history
  • Loading branch information
kyb3r committed Jan 25, 2019
1 parent d42532f commit 3bf2394
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 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.11.0

### Added

- `loglink` command, returns the log link for the current thread.

# v2.10.2
- Your logs now track and show edited messages.

Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""

__version__ = '2.10.2'
__version__ = '2.11.0'

import asyncio
import uvloop
Expand Down
10 changes: 10 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ async def nsfw(self, ctx):
return
await ctx.channel.edit(nsfw=True)
await ctx.message.add_reaction('✅')

@commands.command()
async def loglink(self, ctx):
thread = await self.bot.threads.find(channel=ctx.channel)
if thread:
log_link = await self.bot.modmail_api.get_log_link(ctx.channel.id)
await ctx.send(embed=discord.Embed(
color=discord.Color.blurple(),
description=log_link)
)

@commands.command(aliases=['threads'])
@commands.has_permissions(manage_messages=True)
Expand Down
13 changes: 11 additions & 2 deletions core/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def get_user_logs(self, user_id):

def get_log(self, channel_id):
return self.request(self.logs + '/' + str(channel_id))

async def get_log_link(self, channel_id):
doc = await self.get_log(channel_id)
return f'https://logs.modmail.tk/{doc["key"]}'

def get_config(self):
return self.request(self.config)
Expand All @@ -131,7 +135,7 @@ def update_config(self, data):
data = {k: v for k, v in data.items() if k in valid_keys}
return self.request(self.config, method='PATCH', payload=data)

def get_log_url(self, recipient, channel, creator):
def create_log_entry(self, recipient, channel, creator):
return self.request(self.logs + '/key', payload={
'channel_id': str(channel.id),
'guild_id': str(self.app.guild_id),
Expand Down Expand Up @@ -218,8 +222,13 @@ 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_link(self, channel_id):
doc = await self.get_log(channel_id)
key = doc['key']
return f"{self.app.config.log_url.strip('/')}/logs/{key}"

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

await self.logs.insert_one({
Expand Down
5 changes: 2 additions & 3 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class ConfigManager:
"""Class that manages a cached configuration"""

allowed_to_change_in_command = {
'activity_message', 'activity_type', 'log_channel_id',
'mention', 'disable_autoupdates', 'prefix',
'log_channel_id', 'mention', 'disable_autoupdates', 'prefix',
'main_category_id', 'sent_emoji', 'blocked_emoji',
'thread_creation_response', 'twitch_url', 'mod_color',
'recipient_color', 'mod_tag', 'anon_username', 'anon_avatar_url',
Expand All @@ -18,7 +17,7 @@ class ConfigManager:
internal_keys = {
'snippets', 'aliases', 'blocked',
'notification_squad', 'subscriptions',
'closures'
'closures', 'activity_message', 'activity_type'
}

protected_keys = {
Expand Down
2 changes: 1 addition & 1 deletion core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ async def create(self, recipient, *, creator=None, category=None):
thread.channel = channel

log_url, log_data = await asyncio.gather(
self.bot.modmail_api.get_log_url(recipient, channel, creator or recipient),
self.bot.modmail_api.create_log_entry(recipient, channel, creator or recipient),
self.bot.modmail_api.get_user_logs(recipient.id)
# self.get_dominant_color(recipient.avatar_url)
)
Expand Down

0 comments on commit 3bf2394

Please sign in to comment.