Skip to content

Commit

Permalink
added logging support for Todo
Browse files Browse the repository at this point in the history
  • Loading branch information
s0lst1ce committed May 7, 2019
1 parent c21c607 commit 9749a82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,30 @@ def __init__(self, bot):


@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
async def on_raw_reaction_add(self, payload):
'''currently makes this checks for ALL channels. Might want to change the behavior to allow reactions on other msgs'''

if not self.poll_allowed_chans[reaction.message.guild.id]:
local_logger.warning("Guild {0.name}[{0.id}] doesn't have any channel for polls".format(reaction.message.guild))
print(payload.emoji.name)
if not self.poll_allowed_chans[payload.guild_id]:
local_logger.warning("Guild [{0.id}] doesn't have any channel for polls".format(payload.guild_id))
return


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

#checking if reaction is allowed
if reaction.emoji not in [EMOJIS["thumbsdown"],EMOJIS["thumbsup"],EMOJIS["shrug"]]:
if payload.emoji.name not in [EMOJIS["thumbsdown"],EMOJIS["thumbsup"],EMOJIS["shrug"]]:
#deleting reaction of the user. Preserves other reactions
try:
await reaction.remove(user)
message = self.bot.get_message(payload.message_id)
user = self.bot.get_user(payload.user_id)
for reaction in message.reactions:
if reaction.emoji == payload.emoji:
await reaction.remove(user)
except Exception as e:
local_logger.exception("Couldn't remove reaction {}".format("reaction"))
raise e


@commands.Cog.listener()
Expand All @@ -74,14 +80,14 @@ async def on_message(self, message):

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 ?",
title = "{}{}".format(message.author.name, message.author.avatar_url),
description = message.content,
colour = discord.Color(7726379),
url = None
)

#embed_poll.set_thumbnail(url=message.author.avatar_url)
embed_poll.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
#embed_poll.set_footer(text=message.author.name, icon_url=message.author.avatar_url)

try:
await message.delete()
Expand Down
13 changes: 13 additions & 0 deletions Todo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import logging
import discord
from settings import *
from checks import *

#########################################
# #
# #
# Setting up logging #
# #
# #
#########################################
local_logger = logging.getLogger(__name__)
local_logger.setLevel(LOGGING_LEVEL)
local_logger.addHandler(LOGGING_HANDLER)
local_logger.info("Innitalized {} logger".format(__name__))

class Todo(commands.Cog):
"""A suite of command to make a nice todo list."""
def __init__(self, bot):
Expand Down

0 comments on commit 9749a82

Please sign in to comment.