@ML1012018ZHENG/

toasted.voter

Python

No description

fork
loading
Files
  • main.py
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import discord
import os

client = discord.Client()
season = 0
@client.event
async def on_ready():
  os.environ["OPTIONNO"]="0"
  print("I'm in")
  print(client.user)
  os.environ["STATE"] = "0"
@client.event
async def on_message(message):
  if discord.utils.get(message.author.roles, name="admin"):
    if os.environ["STATE"] == "0":
      os.environ["ANSWERED"] = ""
      if "tv$vote statement" in message.content:
        words = message.content.split(" ")
        os.environ["STATEMENT"] = message.content.replace("tv$vote statement ", "")
        await message.channel.send("statement set to "+ os.environ["STATEMENT"])
      if "tv$vote option" in message.content:
        words = message.content.split(" ")
        os.environ[str("OPTION" + words[2])] = message.content.replace("tv$vote option " + words[2] + " ", "")
        await message.channel.send("OPTION" + words[2]+" set to " + os.environ["OPTION" + words[2]])
        os.environ["OPTIONNO"] = str(int(os.environ["OPTIONNO"]) + 1)
      if "tv$vote start" in message.content:
        options = ""
        for i in range(0, int(os.environ["OPTIONNO"])):
          options = str(options + ";option " + str(i) + " is " + os.environ["OPTION" + str(i + 1)])
          os.environ["STATE"]="1"
        await message.channel.send(str(os.environ["STATEMENT"] + options))
    elif os.environ["STATE"] == "1":
      if "tv$vote vote" in message.content:
        try:
          if os.environ[str(message.author.name).upper()] != "":
            await message.channel.send(str(message.author.name) + " you have already answered")
        except:
          words = message.content.split(" ")
          os.environ["ANSWERED"] += "," + str(message.author.name)
          os.environ[str(message.author.name).upper()] = words[2]
          await message.channel.send("Done")
      if discord.utils.get(message.author.roles, name="admin"):
        if "tv$vote end" == message.content:
          answers = []
          answeruser = os.environ["ANSWERED"].split(",")
          for i in range(0, int(os.environ["ANSWERED"])):
            answers[int(os.environ[answeruser[i].upper()])] = answers[int(os.environ[answeruser[i].upper()])] + 1
          await message.channel.send(answers)
     
token = os.environ.get("DISCORD_BOT_SECRET")
client.run(token)