Re-add multi-channel support

This commit is contained in:
Daniel Mason 2020-03-22 08:44:54 +13:00
parent 05e10e852a
commit 1144a4cb2f
3 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,4 @@
DISCORD_TOKEN="" DISCORD_TOKEN=""
DISCORD_CHANNEL="" DISCORD_CHANNELS=""
SOURCE_CHANNEL="" SOURCE_CHANNEL=""
REGEX_MATCH="^.*(K41|COVID).*$" REGEX_MATCH="^.*(K41|COVID).*$"

View File

@ -17,7 +17,7 @@ copy .env.example to .env and setup your user Token in .env
.env file layout .env file layout
DISCORD_TOKEN="token_from_web" DISCORD_TOKEN="token_from_web"
DISCORD_CHANNELS="channel_1_id" DISCORD_CHANNELS="channel_1_id,channel_2_id"
SOURCE_CHANNEL="channel_id_to_listen_to" SOURCE_CHANNEL="channel_id_to_listen_to"
REGEX_MATCH="^.*(REGEX|TO|USE|TO|MATCH).*$" REGEX_MATCH="^.*(REGEX|TO|USE|TO|MATCH).*$"

4
bot.py
View File

@ -12,7 +12,9 @@ class MyClient(discord.Client):
async def on_message(self, message): async def on_message(self, message):
if message.channel.id == int(os.getenv("SOURCE_CHANNEL")): if message.channel.id == int(os.getenv("SOURCE_CHANNEL")):
if re.match(os.getenv("REGEX_MATCH"), message.content, re.IGNORECASE): if re.match(os.getenv("REGEX_MATCH"), message.content, re.IGNORECASE):
channel = client.get_channel(int(os.getenv("DISCORD_CHANNEL"))) chan_list = [x.strip() for x in os.getenv("DISCORD_CHANNELS").split(',')]
for channel_id in chan_list:
channel = client.get_channel(int(channel_id))
await channel.send(message.content) await channel.send(message.content)
load_dotenv() load_dotenv()