|
|
|
@ -3,10 +3,20 @@ import re
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
|
import twitter
|
|
|
|
|
|
|
|
|
|
from commands import CommandError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @everyone Lilia is Live! Playing $game ! Come and say hi at $url !
|
|
|
|
|
ANNOUNCEMENT_PATTERN = re.compile(r'''^
|
|
|
|
|
@everyone\s+
|
|
|
|
|
Lilia\s+is\s+Live!\s+
|
|
|
|
|
Playing\s+(?P<game>.+)\s+!\s+
|
|
|
|
|
Come\s+and\s+say\s+hi\s+at\s+(?P<url>.+)\s+!
|
|
|
|
|
$''', re.VERBOSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cooldown(retries, timeout, failure):
|
|
|
|
|
def do_cooldown(function):
|
|
|
|
|
def wrapper(self, server, user, *args, **kwargs):
|
|
|
|
@ -37,6 +47,11 @@ class DiscordClient(discord.Client):
|
|
|
|
|
self.logger = logger
|
|
|
|
|
self.commands = commands
|
|
|
|
|
self.extra_commands = extra_commands
|
|
|
|
|
self.twitter_api = twitter.Api(
|
|
|
|
|
consumer_key=self.config['Twitter'].get('consumer_key'),
|
|
|
|
|
consumer_secret=self.config['Twitter'].get('consumer_secret'),
|
|
|
|
|
access_token_key=self.config['Twitter'].get('access_token_key'),
|
|
|
|
|
access_token_secret=self.config['Twitter'].get('access_token_secret'))
|
|
|
|
|
self.supported_commands = [
|
|
|
|
|
(re.compile(r'^!lastquote$'), self._do_lastquote),
|
|
|
|
|
(re.compile(r'^!findquote\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_findquote),
|
|
|
|
@ -74,9 +89,14 @@ class DiscordClient(discord.Client):
|
|
|
|
|
async for msg in self.logs_from(channel, after=after):
|
|
|
|
|
if msg.content == message.content:
|
|
|
|
|
return
|
|
|
|
|
embed = next(iter(message.embeds or []), None)
|
|
|
|
|
await self.send_message(channel, message.content, tts=message.tts, embed=embed)
|
|
|
|
|
# TODO: twitter
|
|
|
|
|
try:
|
|
|
|
|
await self.send_message(channel, message.content)
|
|
|
|
|
except discord.errors.Forbidden:
|
|
|
|
|
pass
|
|
|
|
|
announcement = self.config['Twitter'].get('announcement_pattern')
|
|
|
|
|
m = ANNOUNCEMENT_PATTERN.match(message.content)
|
|
|
|
|
if m:
|
|
|
|
|
self.twitter_api.PostUpdate(announcement.format(**m.groupdict()))
|
|
|
|
|
|
|
|
|
|
async def _cooldown_failure(self, server, user, message, **kwargs):
|
|
|
|
|
await self.send_message(message.channel,
|
|
|
|
|