Implement announcement tweeting

master
Nikola Forró 6 years ago
parent e549cc9f1b
commit e27b138170

@ -3,10 +3,20 @@ import re
import time import time
import discord import discord
import twitter
from commands import CommandError 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 cooldown(retries, timeout, failure):
def do_cooldown(function): def do_cooldown(function):
def wrapper(self, server, user, *args, **kwargs): def wrapper(self, server, user, *args, **kwargs):
@ -37,6 +47,11 @@ class DiscordClient(discord.Client):
self.logger = logger self.logger = logger
self.commands = commands self.commands = commands
self.extra_commands = extra_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 = [ self.supported_commands = [
(re.compile(r'^!lastquote$'), self._do_lastquote), (re.compile(r'^!lastquote$'), self._do_lastquote),
(re.compile(r'^!findquote\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_findquote), (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): async for msg in self.logs_from(channel, after=after):
if msg.content == message.content: if msg.content == message.content:
return return
embed = next(iter(message.embeds or []), None) try:
await self.send_message(channel, message.content, tts=message.tts, embed=embed) await self.send_message(channel, message.content)
# TODO: twitter 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): async def _cooldown_failure(self, server, user, message, **kwargs):
await self.send_message(message.channel, await self.send_message(message.channel,

@ -3,4 +3,5 @@ fuzzywuzzy[speedup]
google-api-python-client google-api-python-client
irc irc
python-dateutil python-dateutil
python-twitter
requests requests

@ -11,6 +11,13 @@ announcer = 369539730989252609
# #cheesenouncements # #cheesenouncements
announcement_channels = 383778221004554249,352145992256061440 announcement_channels = 383778221004554249,352145992256061440
[Twitter]
consumer_key = __TWITTER_CONSUMER_KEY__
consumer_secret = __TWITTER_CONSUMER_SECRET__
access_token_key = __TWITTER_ACCESS_TOKEN_KEY__
access_token_secret = __TWITTER_ACCESS_TOKEN_SECRET__
announcement_pattern = Live now! Playing {game} - Bring Cheese! {url}
[Twitch] [Twitch]
cache_api_url = https://ladylilia.com/twitch-cache/api cache_api_url = https://ladylilia.com/twitch-cache/api
token = oauth:__TWITCH_OAUTH_TOKEN__ token = oauth:__TWITCH_OAUTH_TOKEN__

Loading…
Cancel
Save