Implement distribution of announcements

master
Nikola Forró 6 years ago
parent 41a0685ca6
commit e549cc9f1b

@ -1,3 +1,4 @@
import datetime
import re
import time
@ -53,6 +54,7 @@ class DiscordClient(discord.Client):
self.logger.info('Logged in as {0}'.format(self.user.name))
async def on_message(self, message):
await self._process_announcement(message)
server = message.server.id if message.server else None
for pattern, action in self.supported_commands:
m = pattern.match(message.content)
@ -62,6 +64,20 @@ class DiscordClient(discord.Client):
if cmd == message.content:
await self.send_message(message.channel, resp.format(user=message.author.mention))
async def _process_announcement(self, message):
announcer = self.config['Discord'].get('announcer')
channels = self.config['Discord'].get('announcement_channels').split(',')
if message.author.id != announcer or message.channel.id not in channels:
return
after = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
for channel in [discord.Object(c) for c in channels if c != message.channel.id]:
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
async def _cooldown_failure(self, server, user, message, **kwargs):
await self.send_message(message.channel,
'Sorry {0}, you have to wait a while before running '

@ -6,6 +6,10 @@ channels = lilialil
[Discord]
token = __DISCORD_TOKEN__
# Bellateeny
announcer = 369539730989252609
# #cheesenouncements
announcement_channels = 383778221004554249,352145992256061440
[Twitch]
cache_api_url = https://ladylilia.com/twitch-cache/api

Loading…
Cancel
Save