Skip to content
Permalink
Browse files
Commented code and removed nacl.py because the code is added directly…
… to chatbot.py rather than imported
  • Loading branch information
masudm6 committed Nov 5, 2020
1 parent 23d1e50 commit b518e661cecf25ca956bafd9a0ec72d8e8427ce3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 53 deletions.
@@ -23,7 +23,7 @@ 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
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
@@ -42,40 +42,45 @@ async def on_message(message): #checks for a message
response = random.choice(creepyHellos)
await message.channel.send(response)

# Masud did this

#if message.content.lower()[4:] == "salt":
if "salt" in message.content.lower():
communityName = (message.content)[5:]
poll = await message.channel.send(f'vote here for {communityName}:')
print(f'[BOT DEBUG] {communityName} added to list of polls')
polls[poll.id] = communityName.upper()
print(polls)
tickEmoji = "\u2705"
crossEmoji = "\u274C"
await poll.add_reaction(tickEmoji)
await poll.add_reaction(crossEmoji)

if "count" in message.content.lower():
communityName = (message.content)[6:]

if communityName.upper() not in polls.values():
await message.channel.send(f'No poll found for community: {communityName}.')
else:
# ================ Masud did this ================

tickEmoji = "\u2705" # unicode for the tick Emoji
crossEmoji = "\u274C" # unicode for the cross Emoji

if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt "
communityName = (message.content)[5:] # saves the rest of the input as communityName

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(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

if "count " == (message.content.lower())[:6]: # cecks if the input matches "count "
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
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())]
pollMessage = await message.channel.fetch_message(pollID)
pollReactions = pollMessage.reactions

await message.channel.send(f'Here are the saltiness statistics for the community {communityName}\nPoll ID:{pollID}')
for emj in pollReactions:
emojiCount = emj.count - 1
if emojiCount == 1:
pollID = list(polls.keys())[list(polls.values()).index(communityName.upper())] # get the pollID with the matching communityName
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
for emj in pollReactions: # for each emoji in the reactions object
emojiCount = emj.count - 1 # remove 1 vote, which was from the bot.
if emojiCount == 1: # message to discord accordingly
await message.channel.send(f'{emj.emoji} : {emojiCount} vote')
else:
await message.channel.send(f'{emj.emoji} : {emojiCount} votes')

# up to about here
# ================ up to about here ================


client.run(TOKEN) #this is the token of the discord bot. You can create your own bot and put that token in here or the .env file to run the code
23 nacl.py

This file was deleted.

0 comments on commit b518e66

Please sign in to comment.