Last active
August 19, 2017 02:27
-
-
Save slice/ce58e647352efb7c9b273f36794bf243 to your computer and use it in GitHub Desktop.
A Disco plugin for automatically checking rowboat join logs for users with Nitro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from disco.bot.command import CommandLevels | |
from disco.bot import Plugin, Config | |
JOIN_REGEX = re.compile(r'(:inbox_tray:|📥) (.+)#(\d{4}) \((\d+)\) joined ?(.+)') | |
class NitroCheckerConfig(Config): | |
joins_channel = None | |
ok_emoji = 'ya:318595000311087105' | |
@Plugin.with_config(NitroCheckerConfig) | |
class NitroCheckerPlugin(Plugin): | |
def load(self, ctx): | |
super(NitroCheckerPlugin, self).load(ctx) | |
self.analytics = self.storage.plugin('analytics') | |
@Plugin.listen('MessageCreate') | |
def on_msg(self, msg): | |
# ignore messages not sent in the designated joins channel | |
if msg.channel.id != self.config.joins_channel: | |
return | |
match = JOIN_REGEX.search(msg.content) | |
if match is None: | |
return | |
username, discriminator, snowflake = match.groups()[1:4] | |
snowflake = int(snowflake) | |
if snowflake not in self.state.users: | |
self.log.warning("Attempted to fetch information for user %d, wasn't in state.", snowflake) | |
return | |
user = self.state.users[snowflake] | |
if 'a_' in user.avatar_url or '.gif' in user.avatar_url: | |
# animated | |
msg.add_reaction(self.config.ok_emoji) | |
self.analytics['automated_approvals'] = self.analytics.get('automated_approvals', 0) + 1 | |
self.log.info('Automatically approved %s#%s (%d)', username, discriminator, snowflake) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment