forked from LoganTutt/StratBotPublic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strat-bot.py
173 lines (127 loc) · 4.02 KB
/
strat-bot.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import discord
import random
from gsheet import Sheet
import datetime
# import asyncio
print(discord.version_info)
client = discord.Client()
user = []
voices = []
token = open("token.txt","r").readline()
UPDATE_RATE=30 #Minutes between updates
sheet = Sheet()
stratDatabase = sheet.get_table()
last_update = datetime.datetime.now()
def update_if_needed(database):
global last_update
now = datetime.datetime.now()
if (now - last_update).total_seconds() > UPDATE_RATE*60:
print("Updating database")
last_update = now
return sheet.get_table()
else:
return database
@client.event
async def on_ready():
print("We have logged in as {0.user}".format(client))
@client.event
async def on_message(message):
global stratDatabase
messageStr = message.content
messageStr = messageStr.lower()
if message.author == client.user:
return
if message.content.startswith("!strat"): #Checking if strat
stratDatabase = update_if_needed(stratDatabase)
validNum = False
if attacker(messageStr): #Checking if Attacker
if cstore(messageStr):
while validNum == False:
validNum = randomGen("Attackers","C-Store")
await message.channel.send(embed=post(validNum)) #Attacker CS
print("att cs")
return
if factory(messageStr):
while validNum == False:
validNum = randomGen("Attackers","Factory")
await message.channel.send(embed=post(validNum)) #Attacker Factory
print("att fac")
return
if killhouse(messageStr):
while validNum == False:
validNum = randomGen("Attackers","Killhouse")
await message.channel.send(embed=post(validNum)) #Attacker Killhouse
print("att kh")
return
if defender(messageStr): #Checking if Defender
if cstore(messageStr):
while validNum == False:
validNum = randomGen("Defenders","C-store")
await message.channel.send(embed=post(validNum)) #Defender CS
print("def cs")
return
if factory(messageStr):
while validNum == False:
validNum = randomGen("Defenders","Factory")
await message.channel.send(embed=post(validNum)) #Defender Factory
print("def fac")
return
if killhouse(messageStr):
while validNum == False:
validNum = randomGen("Defenders","Killhouse")
await message.channel.send(embed=post(validNum)) #Defender Killhouse
print("def kh")
return
validNum = randomGen("Both","All")
await message.channel.send(embed=post(validNum))
print("general")
if message.content.startswith("!help"):
await message.channel.send("`!strat [team] [tile set]`. \n You can do just `!strat` for a general strat, or specify both a team and a tileset which can give you a strat for the map or the team.")
def randomGen(team,tileset):
num = random.randint(0,len(stratDatabase))
if team == "Both":
return num
if (not "Both" in stratDatabase[num][2]) and (not team in stratDatabase[num][2]):
return False
if (not "All" in stratDatabase[num][3]) and (not tileset in stratDatabase[num][3]):
return False
return num
#random number gen from 1 to length of list
#check the team is right, return false if not
#check the tileset is right, return false if not
#return number
def post(number):
embed = discord.Embed(title="Title (GDOCS)", description=stratDatabase[number][0], color=0x04ddfe)
embed.add_field(name="Description", value=stratDatabase[number][1], inline=False)
embed.add_field(name="Team", value=stratDatabase[number][2], inline=False)
embed.add_field(name="TileSet", value=stratDatabase[number][3], inline=False)
return embed
def attacker(message):
if "atk" in message:
return True
if "attack" in message:
return True
if "cop" in message:
return True
return False
def defender(message):
if "crim" in message:
return True
if "def" in message:
return True
return False
def cstore(message):
if "cs" in message:
return True
return False
def factory(message):
if "fac" in message:
return True
return False
def killhouse(message):
if "kill" in message:
return True
if "kh" in message:
return True
return False
client.run(token.strip())