Skip to content

Instantly share code, notes, and snippets.

@AceSevenFive
Created May 20, 2018 15:38
Show Gist options
  • Save AceSevenFive/8c1861cc38e2f78bbcd524ec8ca805cf to your computer and use it in GitHub Desktop.
Save AceSevenFive/8c1861cc38e2f78bbcd524ec8ca805cf to your computer and use it in GitHub Desktop.
async def countVotes(submission, message, viewRawVotes):
embed=discord.Embed(title="CMHOC Clerk")
votedict = {"Bills": [x[0].replace(": Y", "") for x in re.findall("([CSM]\-\d\d(\s\w\d:|:)\sY)", submission.selftext)], "Unknown Votes": {}, "Raw Votes": {}}
for x in votedict["Bills"]:
votedict[x] = {"Yea": 0, "Nay": 0, "Abstain": 0}
for x in re.findall("((C|S|M)-(\d+:|\d+\s\w\d:)\s)([Yy]ea|[Nn]ay|[Aa]bstain|[Oo]ui|[Nn]on|[Aa]bstention)", "".join([y for y in [x.body.replace("\n", "") for x in submission.comments] if not re.match("^P", y)])):
print(x[0])
if(x[0].replace(": ", "") in votedict["Bills"]):
if(x[3] in ["Yea", "yea", "Oui", "oui"]):
votedict[x[0].replace(": ", "")]["Yea"] += 1
elif(x[3] in ["Nay", "nay", "Non", "non"]):
votedict[x[0].replace(": ", "")]["Nay"] += 1
elif(x[3] in ["Abstain", "abstain", "Abstention", "abstention"]):
votedict[x[0].replace(": ", "")]["Abstain"] += 1
for x in submission.comments:
if(re.search("((C|S|M)-(\d+:|\d+\s\w\d:)\s)([Yy]ea|[Nn]ay|[Aa]bstain|[Oo]ui|[Nn]on|[Aa]bstention)", x.body) is None):
votedict["Unknown Votes"][x.author.name] = x.body
else:
votedict["Raw Votes"][x.author.name] = x.body
for x in votedict["Bills"]:
embed.add_field(name=x, value=x + ": " + str(votedict[x]["Yea"]) + " Yea, " + str(votedict[x]["Nay"]) + " Nay, " + str(votedict[x]["Abstain"]) + " Abstentions", inline=False)
if(viewRawVotes == True):
for k, v in votedict["Raw Votes"].items():
if(k != "AutoModerator"):
await client.send_message(message.author, k + ": " + v)
await client.send_message(message.channel, embed=embed)
if(len(votedict["Unknown Votes"]) > 1):
client.send_message(message.channel, "Unknown votes have been detected. To view them, type %viewunknowns.")
msg = await client.wait_for_message(timeout=15, author=message.author, content="%viewunknowns")
if(msg is not None):
embed=discord.Embed(title="CMHOC Clerk")
for k, v in votedict["Unknown Votes"].items():
if(k != "AutoModerator"):
embed.add_field(name=k, value=v)
await client.send_message(message.channel, embed=embed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment