forked from Simber1/StratBotPublic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrat-bot.py
216 lines (188 loc) · 6.17 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import discord
from discord.ext import commands
import random
from gsheet import Sheet
import datetime
# import asyncio
print(discord.version_info)
token = open("token.txt","r").readline()
#This should work? If not, idk
client = commands.Bot(command_prefix='!', case_insensitive=True, description='memer strat bot.')
client.remove_command('help')
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))
#Let this command be run by people with the Testers role only.
@client.command()
@commands.has_role('Testers')
async def strat(ctx,*args):
#Not sure why this is global but I kept it because who knows.
global stratDatabase
stratDatabase = update_if_needed(stratDatabase)
#I got tired of scrolling. Add your options here
team_options_a = ['a','attack','attk','atk','attackers']
team_options_d = ['d','defender','def','crim','t']
tile_options_c = ['c','cs','cstore','store']
tile_options_f = ['factory','f','fac']
tile_options_k = ['k','kill','killhouse']
teams_merged = team_options_a + team_options_d
tiles_merged = tile_options_c + tile_options_f + tile_options_k
#No arguments provided. Default to random.
if len(args) == 0:
validNum = randomGen("Both","All")
await ctx.send(embed=post(validNum))
return
#One argument provided, check to see if it's a tile
elif len(args) == 1 and args[0].lower() in tiles_merged:
tile = args[0].lower()
#A bunch of if's to determine what tile should be posted.
if tile in tile_options_c:
validNum = randomGen('Both',"C-Store")
await ctx.send(embed=post(validNum))
return
if tile in tile_options_f:
validNum = randomGen('Both',"Factory")
await ctx.send(embed=post(validNum))
return
if tile in tile_options_k:
validNum = randomGen('Both',"Killhouse")
await ctx.send(embed=post(validNum))
return
#Like above, but for teams if this is the only argument passed
elif len(args) == 1 and args[0].lower() in teams_merged:
team = args[0].lower()
if team in team_options_a:
validNum = randomGen("Attackers","All")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","All")
await ctx.send(embed=post(validNum))
return
#tile was first argument, team was second
elif len(args) == 2 and args[0].lower() in tiles_merged and args[1].lower() in teams_merged:
tile = args[0].lower()
team = args[1].lower()
if tile in tile_options_c:
if team in team_options_a:
validNum = randomGen("Attackers","C-Store")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","C-Store")
await ctx.send(embed=post(validNum))
return
elif tile in tile_options_f:
if team in team_options_a:
validNum = randomGen("Attackers","Factory")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","Factory")
await ctx.send(embed=post(validNum))
return
elif tile in tile_options_k:
if team in team_options_a:
validNum = randomGen("Attackers","Killhouse")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","Killhouse")
await ctx.send(embed=post(validNum))
return
#Same as above, but team was the first argument and tile was second
elif len(args) == 2 and args[1] in tiles_merged and args[0] in teams_merged:
tile = args[1].lower()
team = args[0].lower()
if tile in tile_options_c:
if team in team_options_a:
validNum = randomGen("Attackers","C-Store")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","C-Store")
await ctx.send(embed=post(validNum))
return
elif tile in tile_options_f:
if team in team_options_a:
validNum = randomGen("Attackers","Factory")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","Factory")
await ctx.send(embed=post(validNum))
return
elif tile in tile_options_k:
if team in team_options_a:
validNum = randomGen("Attackers","Killhouse")
await ctx.send(embed=post(validNum))
return
else:
validNum = randomGen("Defenders","Killhouse")
await ctx.send(embed=post(validNum))
return
#No need to check to see if the amount of args provided is above 2 since we just wont use them. Also not caring how the list looks when posted.
else:
await ctx.send("You did not enter valid arguments. Valid arguments for team names are:\n`"+str(teams_merged)+"`\n\nValid arguments for tilesets are:\n`"+str(tiles_merged)+"`")
return
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", 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())