Guest User

Untitled

a guest
May 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. async def countVotes(submission, message, viewRawVotes):
  2. embed=discord.Embed(title="CMHOC Clerk")
  3. votedict = {"Bills": [x[0].replace(": Y", "") for x in re.findall("([CSM]\-\d\d(\s\w\d:|:)\sY)", submission.selftext)], "Unknown Votes": {}, "Raw Votes": {}}
  4. for x in votedict["Bills"]:
  5. votedict[x] = {"Yea": 0, "Nay": 0, "Abstain": 0}
  6. 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)])):
  7. print(x[0])
  8. if(x[0].replace(": ", "") in votedict["Bills"]):
  9. if(x[3] in ["Yea", "yea", "Oui", "oui"]):
  10. votedict[x[0].replace(": ", "")]["Yea"] += 1
  11. elif(x[3] in ["Nay", "nay", "Non", "non"]):
  12. votedict[x[0].replace(": ", "")]["Nay"] += 1
  13. elif(x[3] in ["Abstain", "abstain", "Abstention", "abstention"]):
  14. votedict[x[0].replace(": ", "")]["Abstain"] += 1
  15. for x in submission.comments:
  16. 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):
  17. votedict["Unknown Votes"][x.author.name] = x.body
  18. else:
  19. votedict["Raw Votes"][x.author.name] = x.body
  20. for x in votedict["Bills"]:
  21. embed.add_field(name=x, value=x + ": " + str(votedict[x]["Yea"]) + " Yea, " + str(votedict[x]["Nay"]) + " Nay, " + str(votedict[x]["Abstain"]) + " Abstentions", inline=False)
  22. if(viewRawVotes == True):
  23. for k, v in votedict["Raw Votes"].items():
  24. if(k != "AutoModerator"):
  25. await client.send_message(message.author, k + ": " + v)
  26. await client.send_message(message.channel, embed=embed)
  27. if(len(votedict["Unknown Votes"]) > 1):
  28. client.send_message(message.channel, "Unknown votes have been detected. To view them, type %viewunknowns.")
  29. msg = await client.wait_for_message(timeout=15, author=message.author, content="%viewunknowns")
  30. if(msg is not None):
  31. embed=discord.Embed(title="CMHOC Clerk")
  32. for k, v in votedict["Unknown Votes"].items():
  33. if(k != "AutoModerator"):
  34. embed.add_field(name=k, value=v)
  35. await client.send_message(message.channel, embed=embed)
Add Comment
Please, Sign In to add comment