Skip to content

Commit

Permalink
Poll: switched from using channel/guild/member names to ids
Browse files Browse the repository at this point in the history
  • Loading branch information
s0lst1ce committed May 6, 2019
1 parent c0b50db commit c21c607
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions Poll.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging
import discord
from settings import *
Expand Down Expand Up @@ -31,12 +32,18 @@ class Poll(commands.Cog):
def __init__(self, bot):
self.bot = bot

#making sure POLL_ALLOWED_CHANNELS_FILE exists
if POLL_ALLOWED_CHANNELS_FILE not in os.listdir():
local_logger.warning("{} doesn't exist & not configured".format(POLL_ALLOWED_CHANNELS_FILE))
with open(POLL_ALLOWED_CHANNELS_FILE, "w") as file:
pass

#making poll_allowed channels according to the message's guild
self.poll_allowed_chans = {}
with open(POLL_ALLOWED_CHANNELS_FILE) as file:
with open(POLL_ALLOWED_CHANNELS_FILE, "r") as file:
for line in file.readlines():
guild_id = line.split(";")[0]
self.poll_allowed_chans[guild_id] = [chan_id for chan_id in line.split(";")[1:]]
guild_id = int(line.split(";")[0])
self.poll_allowed_chans[guild_id] = [int(chan_id) for chan_id in line.split(";")[1:]]



Expand All @@ -50,7 +57,6 @@ async def on_reaction_add(self, reaction, user):


#checking that user isn't the bot
print(reaction.message.channel.name)
if (user != self.bot.user) and (reaction.message.channel.id in self.poll_allowed_chans[reaction.message.guild.id]):

#checking if reaction is allowed
Expand All @@ -66,7 +72,7 @@ async def on_reaction_add(self, reaction, user):
async def on_message(self, message):
if message.author==self.bot.user: return

if message.channel.name in and message.content.startswith(PREFIX)!=True:
if message.channel.id in self.poll_allowed_chans[message.guild.id] and message.content.startswith(PREFIX)!=True:
embed_poll = discord.Embed(
title = "Do you agree ?",
description = message.content,
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


PREFIX = "::"
TOKEN = "your_token"
TOKEN = "NTYzODQ4MDcxMjE0MjY4NDI5.XMj3MA.yF2biw9arAeVyZiON30-y2oQV1w"
AUTHOR_ID=289426079544901633


Expand Down

0 comments on commit c21c607

Please sign in to comment.