From 127b99c4febd59b4ba10d630e1b295682f041273 Mon Sep 17 00:00:00 2001 From: Ben Herrick-Blake Date: Sun, 22 Nov 2020 16:31:49 +0000 Subject: [PATCH 1/4] kk haha funny lolz --- Chatbot.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index bf80438..1fce0fd 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -164,6 +164,35 @@ def registerSteamID(message, discordID): else: return("To link your steam requires a SteamID64 a guide for which can be found at: https://appuals.com/steam-64-id/") #SteamID END + +#ChangeSteamID START +def changeSteamID(message, discordID): #Changes a registered users steamID to whatever new id they input. + sharedRelationshipIndex = tempIDArrayDiscord.index(discordID) + formattedSteamID = message.lower() + formattedSteamID = formattedSteamID.replace(" ","") #Formats the recieved message into an acceptable form for the program to iterate through + for charNum in range(len(formattedSteamID)): + if charNum == 0: + count = 0 + adjacencyStartIndex = 0 + currentChar = formattedSteamID[charNum] + if currentChar.isdigit(): + count = count + 1 + else: + count = 0 + adjacencyStartIndex = charNum + 1 + if count == 17: + formattedSteamID = formattedSteamID[adjacencyStartIndex:charNum+1] + break + if len(formattedSteamID) == 17 and formattedSteamID.isdigit(): #and formattedSteamID.is_valid(): in the documentation but currently doesn't work + if (formattedSteamID not in tempIDArraySteam): + tempIDArraySteam[sharedRelationshipIndex] = formattedSteamID #This checks if the input steamID is valid and not already present in the database / two sorted lists that simulate a database + return("Thank You! \nI have now changed your SteamID! It is currently registered as " +formattedSteamID) + elif formattedSteamID in tempIDArraySteam: + return("This Steam ID is already taken sorry") + else: + return ("Sorry, I couldn't seem to find the new SteamID") +#ChangeSteamID END + #SpecificGameID START def fetchGameID(gameName): #This function fetches the appID of specific game on steam based on the name the user inputs gameName = gameName[gameName.find('(') +1 :gameName.find(')')]#Formats the recieved message so as to only search with text in between the brackets when looking for gameID @@ -341,10 +370,13 @@ async def on_message(message): #checks for a message # ================ up to about here ================ #BenHB Start================================================================== #These ifs are used to access a function when a user gives a valid input - if ' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower(): - messageInfo = registerSteamID(message.content, message.author.id) - await message.channel.send(messageInfo) - + if (' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower()) and message.author.id not in tempIDArrayDiscord: + output = registerSteamID(message.content, message.author.id) + await message.channel.send(output) + if (' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower()) and 'change' in message.content.lower() and 'my' in message.content.lower() and message.author.id in tempIDArrayDiscord: + output = changeSteamID(message.content, message.author.id) + await message.channel.send(output) + if 'displayid ' in message.content.lower(): displayedID = fetchGameID(message.content.replace('displayid ','')) await message.channel.send(displayedID) From 70498dda74b5c6c0c4ff71293e2fecd36577b7fb Mon Sep 17 00:00:00 2001 From: mohammed masud Date: Sun, 22 Nov 2020 17:50:47 +0000 Subject: [PATCH 2/4] converting code to functions --- Chatbot.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index ef79c80..553b916 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -251,7 +251,29 @@ def timeFormat(timePlayed, message, parsedLetters, letterIndex):# A recursive fu #TimeFormatted END #==================Ben=HB=Function=End================== - + +#masud will do some functions here +def createPoll(message): + communityName = (message.content)[5:] # saves the rest of the input as communityName + + await message.add_reaction("🆗") # devops work item 35 + + 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 + polls[poll.id] = communityName.upper() # save the pollID and communityName together + # 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 + +def countPoll(): + pass + +#end of the functions masud did #==================END OF DEFINITIONS=================== @@ -310,20 +332,7 @@ 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 - - await message.add_reaction("🆗") # devops work item 35 - - 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 - polls[poll.id] = communityName.upper() # save the pollID and communityName together - # 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 + createPoll() 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 From 057a18ca7197b2c619adb09851a5e1f69b5c092a Mon Sep 17 00:00:00 2001 From: mohammed masud Date: Sun, 22 Nov 2020 17:51:26 +0000 Subject: [PATCH 3/4] converting code to functions --- Chatbot.py | 124 ++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 553b916..c647742 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -252,27 +252,57 @@ def timeFormat(timePlayed, message, parsedLetters, letterIndex):# A recursive fu #==================Ben=HB=Function=End================== -#masud will do some functions here -def createPoll(message): - communityName = (message.content)[5:] # saves the rest of the input as communityName +#masud will do some functions and code here - await message.add_reaction("🆗") # devops work item 35 +polls = {} # masud added this to hold poll data. Can be switched to a database in the future + +def getPollID(message,communityName,polls): 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 - polls[poll.id] = communityName.upper() # save the pollID and communityName together - # 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 - -def countPoll(): - pass + return True, pollID + else: # and if there is not an active poll already... + return False + +def addPoll(poll,communityName): + polls[poll.id] = communityName.upper() # save the pollID and communityName together + return polls + +def makeEmbed(discord, countDesc, communityName): + countEmbed = discord.Embed() # Discord embed object + countEmbed.description = countDesc # add embed description to embed + countEmbed.title = f"Is the community {communityName} salty or supportive?" # title of countEmbed object. DevOps work item 32 + return countEmbed + +def countPoll(message,communityName,pollReactions): + tickCount = 0 + crossCount = 0 + countDesc = "" + + 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." + + return countDesc #end of the functions masud did @@ -290,8 +320,6 @@ async def on_ready(): members = '\n - '.join([member.name for member in guild.members]) print(f'Guild Members:\n - {members}') -polls = {} # masud added this to hold poll data. Can be switched to a database in the future - @client.event async def on_message(message): #checks for a message if message.author == client.user: #makes sure it's a user @@ -310,7 +338,6 @@ async def on_message(message): #checks for a message except: await message.channel.send(noSteamIDErrorReplies()) - banWords = ["banned", "ban", "bans"] if "steam" in message.content.lower() and [entry for entry in banWords if(entry in message.content.lower())]: try: @@ -332,56 +359,37 @@ async def on_message(message): #checks for a message # ================ Masud did this ================ if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt " - createPoll() + communityName = (message.content)[5:] # saves the rest of the input as communityName + await message.add_reaction("🆗") + result = getPollID(message, communityName, polls) + if result == True: + await message.channel.send(f'The community: {communityName} already has a poll active. Poll ID:{result[1]}.') # message to discord + elif result == False: + 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 + addPoll(poll,communityName) + # 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 ". 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 + if getPollID(message, communityName, polls) == False: # checks if the poll does not exist already await message.channel.send(f'No poll found for community: {communityName}.') # messages to discord - else: # if the poll does exist ... - - pollID = list(polls.keys())[list(polls.values()).index(communityName.upper())] # get the pollID with the matching communityName + else: + pollID = getPollID(message, communityName, polls)[1] + pollMessage = await message.channel.fetch_message(pollID) # get the message object with the pollID pollReactions = pollMessage.reactions # accesses the reactions for the pollMessage object - await message.channel.send(f'Here are the saltiness statistics for the community {communityName}\nPoll ID:{pollID}') # message to discord - countEmbed = discord.Embed() # Discord embed object - countDesc = "" # description 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." - + countDesc = countPoll(message, communityName, pollReactions) + countEmbed = makeEmbed(discord,countDesc,communityName) # 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 + await message.channel.send(embed=countEmbed) # send the embed to the channel the message is in + # ================ up to about here ================ - # ================ up to about here ================ #BenHB Start================================================================== #These ifs are used to access a function when a user gives a valid input if ' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower(): From 16da5c0b843bd7f9b31c54202ecd07488637d644 Mon Sep 17 00:00:00 2001 From: mohammed masud Date: Sun, 22 Nov 2020 18:14:09 +0000 Subject: [PATCH 4/4] fixed duplicate poll functionality and commented code. updated the return type for function getPollID. --- Chatbot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 491ad10..e7360a8 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -289,10 +289,10 @@ def getPollID(message,communityName,polls): 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 - return True, pollID + return [True, pollID] else: # and if there is not an active poll already... - return False + return [False,0] def addPoll(poll,communityName): polls[poll.id] = communityName.upper() # save the pollID and communityName together @@ -325,7 +325,7 @@ def countPoll(message,communityName,pollReactions): # 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." + countDesc = countDesc + "\n This community seems to be both supportive and salty." elif tickCount > crossCount: countDesc = countDesc + "\n This community seems to be more supportive." elif tickCount < crossCount: @@ -389,11 +389,11 @@ 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 - await message.add_reaction("🆗") result = getPollID(message, communityName, polls) - if result == True: + if result[0] == True: await message.channel.send(f'The community: {communityName} already has a poll active. Poll ID:{result[1]}.') # message to discord - elif result == False: + else: + await message.add_reaction("🆗") 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 addPoll(poll,communityName) @@ -403,7 +403,7 @@ async def on_message(message): #checks for a message 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 getPollID(message, communityName, polls) == False: # checks if the poll does not exist already + if getPollID(message, communityName, polls)[0] == False: # checks if the poll does not exist already await message.channel.send(f'No poll found for community: {communityName}.') # messages to discord else: pollID = getPollID(message, communityName, polls)[1]