From a7fc0c83548f167ab5293507c1a28c1a0bd9e88e Mon Sep 17 00:00:00 2001 From: mohammed masud Date: Thu, 19 Nov 2020 14:29:02 +0000 Subject: [PATCH] Added devops work item 34, cleared debug print statements and removed variables which used to hold the tick and cross emojis. --- Chatbot.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 5388b91..35456c4 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -84,21 +84,19 @@ async def on_message(message): #checks for a message # ================ Masud did this ================ if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt " communityName = (message.content)[5:] # saves the rest of the input as communityName - tickEmoji = "\u2705" # unicode for the tick Emoji - crossEmoji = "\u274C" # unicode for the cross Emoji if communityName.upper() in polls.values(): # if there is a poll active already pollID = list(polls.keys())[list(polls.values()).index(communityName.upper())] # get the ID of the poll await message.channel.send(f'The community: {communityName} already has a poll active. Poll ID:{pollID}.') # message to discord else: # and if there is not an active poll already... poll = await message.channel.send(f'vote here for {communityName}:') # create the vote poll - print(f'[BOT DEBUG] {communityName} added to list of polls') # print to console for debugging only + # print(f'[BOT DEBUG] {communityName} added to list of polls') # print to console for debugging only polls[poll.id] = communityName.upper() # save the pollID and communityName together - print(polls) # print list of polls active for debugging only - await poll.add_reaction(tickEmoji) # add the tick emoji for the poll - await poll.add_reaction(crossEmoji) # add the cross emoji for the poll + # print("[BOT DEBUG] Poll dict:\n",polls) # print list of polls active for debugging only + await poll.add_reaction("✅") # add the tick emoji for the poll + await poll.add_reaction("❌") # add the cross emoji for the poll - if "count " == (message.content.lower())[:6]: # checks if the input matches "count " + if "count " == (message.content.lower())[:6]: # checks if the input matches "count ". DevOps work item 33 communityName = (message.content)[6:] # saves the rest of the input as communityName if communityName.upper() not in polls.values(): # checks if the poll does not exist already @@ -113,14 +111,34 @@ async def on_message(message): #checks for a message countEmbed = discord.Embed() # Discord embed object countDesc = "" # description of countEmbed object - countEmbed.title = f"Is the community {communityName} toxic?" # title of countEmbed object + countEmbed.title = f"Is the community {communityName} salty or supportive?" # title of countEmbed object. DevOps work item 32 + + tickCount = 0 + crossCount = 0 for emj in pollReactions: # for each emoji in the reactions object emojiCount = emj.count - 1 # remove 1 vote, which was from the bot. + # print("[BOT DEBUG] emj.emoji:",emj.emoji) # debug code for reactions.emoji object + if emj.emoji == "✅": # if emoji is tick emoji + tickCount = emj.count - 1 # this reaction will be tickCount + elif emj.emoji == "❌": # if emoji is cross emoji + crossCount = emj.count - 1 # this reaction will be crossCount + if emojiCount == 1: # adjust embed description accordingly countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} vote' else: countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} votes' + + # add a message to the end of the results depending on the votes for the emojis. DevOps work item 34 + # print("[BOT DEBUG] tick cross :",tickCount,crossCount) # this code was used to debug the tick and cross counts. + if tickCount == crossCount: + countDesc = countDesc + "\n This community seems to be equally supportive and salty." + elif tickCount > crossCount: + countDesc = countDesc + "\n This community seems to be more supportive." + elif tickCount < crossCount: + countDesc = countDesc + "\n This community seems to be more salty." + + # add the description to the embed and message it to the channel. countEmbed.description = countDesc # add embed description to embed await message.channel.send(embed=countEmbed) # send the embed to the channel the message is in