· 6 years ago · Dec 29, 2019, 04:08 AM
1import asyncio
2
3import random
4
5import os
6
7import sqlite3
8
9import discord
10from discord.ext.commands import Bot
11
12
13tableMonitor = sqlite3.connect("ChickenData.sqlite")
14tableMonitorCursor = tableMonitor.cursor()
15
16tableMonitorCursor.execute("CREATE TABLE if not exists chickenfighters (ability text, abilityLvl integer, discordID integer, intelligence integer, name text, special integer, speed integer, strength integer)")
17tableMonitorCursor.execute("CREATE TABLE if not exists chickenusers (id integer, wins integer, losses integer)")
18
19tableMonitor.close()
20
21bot = Bot(command_prefix='*')
22bot.remove_command('help')
23
24fightClub = None
25fightClub2 = None
26fightClub3 = None
27
28class Fight:
29 def __init__(self, person1 : discord.Member, person2 : discord.Member, moves : int = 0):
30 self.p1 = person1
31 self.p2 = person2
32 self.moves = moves
33
34 def moveOne(self):
35 self.moves += 1
36
37 def getMoves(self):
38 return self.moves
39
40
41@bot.event
42async def on_ready():
43 print('----')
44 print('Logged in as')
45 print(bot.user.name)
46 print(bot.user.id)
47 print('----')
48 await bot.change_presence(activity=discord.Activity(name='people fight...', type=3))
49
50
51@bot.event
52async def on_message(msg):
53 global fightClub
54 global fightClub2
55 global fightClub3
56
57 if fightClub != None:
58 if msg.author.id == fightClub.p1.id or msg.author.id == fightClub.p2.id:
59 fightClub.moveOne()
60
61 if fightClub2 != None:
62 if msg.author.id == fightClub2.p1.id or msg.author.id == fightClub2.p2.id:
63 fightClub2.moveOne()
64
65 if fightClub3 != None:
66 if msg.author.id == fightClub3.p1.id or msg.author.id == fightClub3.p2.id:
67 fightClub3.moveOne()
68
69 if msg.channel.id == 600922251415650335: # battlegrounds-1
70 if fightClub != None:
71 #print(f"{msg.author.id} | {fightClub.p1.id} | {fightClub.p2.id}")
72 if msg.author.id == fightClub.p2.id or msg.author.id == fightClub.p1.id:
73 pass
74 elif msg.author.id == 259882923275190272 or msg.author.id == 202560656883449856 or msg.author.id == 554538693096898571 or msg.author.id == 635990205387505697:
75 pass
76 elif msg.author.bot == True:
77 pass
78 else:
79 channel = msg.guild.get_channel(642497921656291348)
80 await channel.send(msg.author.name + ": " + msg.content)
81 await msg.delete()
82
83 if msg.channel.id == 600922295158177792: # battlegrounds-2
84 if fightClub2 != None:
85 #print(f"{msg.author.id} | {fightClub2.p1.id} | {fightClub2.p2.id}")
86 if msg.author.id == fightClub2.p2.id or msg.author.id == fightClub2.p1.id:
87 pass
88 elif msg.author.id == 259882923275190272 or msg.author.id == 202560656883449856 or msg.author.id == 554538693096898571 or msg.author.id == 635990205387505697:
89 pass
90 elif msg.author.bot == True:
91 pass
92 else:
93 channel = msg.guild.get_channel(642497956091789325)
94 await channel.send(msg.author.name + ": " + msg.content)
95 await msg.delete()
96
97 if msg.channel.id == 600922339827384320: # battlegrounds-3
98 if fightClub3 != None:
99 #print(f"{msg.author.id} | {fightClub3.p1.id} | {fightClub3.p2.id}")
100 if msg.author.id == fightClub.p2.id or msg.author.id == fightClub.p1.id:
101 pass
102 elif msg.author.id == 259882923275190272 or msg.author.id == 202560656883449856 or msg.author.id == 554538693096898571 or msg.author.id == 635990205387505697:
103 pass
104 elif msg.author.bot == True:
105 pass
106 else:
107 channel = msg.guild.get_channel(642498072877727774)
108 await channel.send(msg.author.name + ": " + msg.content)
109 await msg.delete()
110
111 await bot.process_commands(msg)
112
113
114@bot.command(name="help")
115async def help(ctx):
116 index = discord.Embed(title="Command Index", color=0xffffff)
117 index.add_field(name="Help", value="*help", inline=False)
118 index.add_field(name="Create Card", value="*create <name> <strength> <intelligence> <speed> \"<ability>\" <ability level> <special> <disordID> <promoted>", inline=False)
119 index.add_field(name="Recall Card", value="*recall <name of character>", inline=False)
120 index.add_field(name="Declare Winner", value="*declare @<winner> @<loser> <battleground number>", inline=False)
121 index.add_field(name="Dice Roll", value="*roll <optional number, defaults to 10 max>", inline=False)
122 index.add_field(name="Purge Messages", value="*purge <amount to purge>", inline=False)
123 await ctx.message.channel.send(embed=index)
124
125@bot.command(name='create')
126async def cardCreate(ctx, name : str = None, strength : int = None, intelligence : int = None, speed : int = None, ability : str = None, abilityLvl : int = None, special : int = None, owner : discord.Member = None, promo : bool = False):
127 role = discord.utils.get(ctx.guild.roles, name='Underboss')
128 if role in ctx.author.roles:
129 if name is not None and strength is not None and intelligence is not None and speed is not None and ability is not None and special is not None and abilityLvl is not None and owner is not None:
130 card = discord.Embed(title="{}'s Stat Card".format(name), color=0xffffff)
131 card.add_field(name='Name', value=name, inline=False)
132 card.add_field(name='Strength', value=strength, inline=False)
133 card.add_field(name='Intelligence', value=intelligence, inline=False)
134 card.add_field(name='Speed', value=speed, inline=False)
135 card.add_field(name='Ablity', value=ability, inline=False)
136 card.add_field(name='Ability Points', value=abilityLvl, inline=False)
137 card.add_field(name='Special', value=special, inline=False)
138
139 try:
140 if strength + intelligence + speed + abilityLvl + special > 26 and promo is False:
141 await ctx.message.channel.send('You have an improper amount of skill points!')
142 else:
143 createConn = sqlite3.connect("ChickenData.sqlite")
144 createCur = createConn.cursor()
145 await ctx.message.channel.send("Character sucessfully saved to database!") # (ability text, abilityLvl integer, discordID text, intelligence integer, name text, special integer, speed integer, strength integer)
146 createCur.execute("INSERT INTO chickenfighters VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (ability, abilityLvl, owner.id, intelligence, name, special, speed, strength))
147 await ctx.channel.send(embed=card)
148 createConn.commit()
149 createConn.close()
150 except discord.Forbidden:
151 await ctx.message.channel.send('I do not have the proper permissions!')
152 else:
153 await ctx.message.channel.send('The command is used as such: `*create <name> <strength> <intelligence> <speed> "<ability>" <ability level> <special> @<owner of card> <promoted>`')
154 else:
155 await ctx.message.delete()
156
157
158@bot.command(name='recall')
159async def cardRecall(ctx, member : discord.Member):
160 role = discord.utils.get(ctx.guild.roles, name='Underboss')
161 if role in ctx.author.roles:
162 recallConn = sqlite3.connect("ChickenData.sqlite")
163 recallCur = recallConn.cursor() # (ability text 0, abilityLvl integer 1, discordID text 2, intelligence integer 3, name text 4, special integer 5, speed integer 6, strength integer 7)
164 recallCur.execute(f"SELECT * FROM chickenfighters WHERE discordID={member.id}")
165 data = recallCur.fetchone()
166 recallConn.close()
167 card = discord.Embed(title="{}'s Stat Card".format(data[4]), color=0xffffff)
168 card.add_field(name='Name', value=data[4], inline=False)
169 card.add_field(name='Strength', value=data[7], inline=False)
170 card.add_field(name='Intelligence', value=data[3], inline=False)
171 card.add_field(name='Speed', value=data[6], inline=False)
172 card.add_field(name='Ablity', value=data[0], inline=False)
173 card.add_field(name='Ability Points', value=data[1], inline=False)
174 card.add_field(name='Special', value=data[5], inline=False)
175 await ctx.message.channel.send(embed=card)
176 else:
177 await ctx.message.delete()
178
179
180@bot.command(name="declare")
181async def winner(ctx, winner : discord.Member = None, loser : discord.Member = None, fightNum : int = None):
182 role = discord.utils.get(ctx.guild.roles, name='Underboss')
183 if role in ctx.author.roles:
184 if winner is not None and loser is not None and fightNum is not None:
185 if fightNum <= 3 and fightNum != 0:
186 DeclareConn = sqlite3.connect("ChickenData.sqlite")
187 declareCur = DeclareConn.cursor()
188 declareCur.execute(f"SELECT * FROM chickenusers WHERE id={winner.id}")
189 winnerRow = declareCur.fetchone()
190 if winnerRow is None:
191 declareCur.execute(f"INSERT INTO chickenusers VALUES ({winner.id}, 1, 0)")
192 declareCur.execute(f"SELECT * FROM chickenusers WHERE id={loser.id}")
193 loserRow = declareCur.fetchone()
194 if loserRow is None:
195 declareCur.execute(f"INSERT INTO chickenusers VALUES ({winner.id}, 0, 1)")
196 declareCur.execute(f"SELECT * FROM chickenusers WHERE id={loser.id}")
197 loserRow = declareCur.fetchone()
198 if loserRow is not None:
199 declareCur.execute(f"UPDATE chickenusers SET losses = losses + 1 WHERE id={loser.id}")
200 declareCur.execute(f"SELECT * FROM chickenusers WHERE id={winner.id}")
201 winnerRow = declareCur.fetchone()
202 if winnerRow is not None:
203 declareCur.execute(f"UPDATE chickenusers SET wins = wins + 1 WHERE id={winner.id}")
204 DeclareConn.commit()
205 DeclareConn.close()
206
207 global fightClub
208 global fightClub2
209 global fightClub3
210
211 if fightNum == 1:
212 await ctx.message.channel.send(f"{winner.name} won in the fight against {loser.name}! :tada: In total it took {fightClub.getMoves() - 1} moves!")
213 if fightNum == 2:
214 await ctx.message.channel.send(f"{winner.name} won in the fight against {loser.name}! :tada: In total it took {fightClub2.getMoves() - 1} moves!")
215 if fightNum == 3:
216 await ctx.message.channel.send(f"{winner.name} won in the fight against {loser.name}! :tada: In total it took {fightClub3.getMoves() - 1} moves!")
217
218 if fightNum == 1:
219 fightClub = None
220 if fightNum == 2:
221 fightClub2 = None
222 if fightNum == 3:
223 fightClub3 = None
224
225 else:
226 await ctx.message.channel.send("You did not properly specify what the battleground number was!")
227 else:
228 await ctx.message.channel.send("The command is used as such: `*declare @<person> @<person> <battlegrounds number>`")
229 else:
230 await ctx.message.delete()
231
232@bot.command(name="stats")
233async def stats(ctx, member : discord.Member = None):
234 if member is None:
235 statsConn = sqlite3.connect("ChickenData.sqlite")
236 statsCur = statsConn.cursor()
237 statsCur.execute(f"SELECT * FROM chickenusers WHERE id={ctx.message.author.id}")
238 data = statsCur.fetchone()
239 statsConn.close()
240 if data == None:
241 await ctx.message.channel.send("You have not lost or won any battles!")
242 pass
243 else:
244 await ctx.message.channel.send(
245 """
246**Wins** - {}
247**Losses** - {}
248 """.format(data[1], data[2]))
249 else:
250 statsConn = sqlite3.connect("ChickenData.sqlite")
251 statsCur = statsConn.cursor()
252 statsCur.execute(f"SELECT * FROM chickenusers WHERE id={ctx.message.author.id}")
253 data = statsCur.fetchone()
254 statsConn.close()
255 if data == None:
256 ctx.message.send("They have not lost or won any battles!")
257 else:
258 await ctx.message.channel.send(
259 """
260**Wins** - {}
261**Losses** - {}
262 """.format(data[1], data[2]))
263
264@bot.command(name='roll')
265async def bigroll(ctx, max : int = None):
266 if max is not None:
267 randomint = random.randint(1, max)
268 await ctx.message.channel.send('The roll was: {}'.format(randomint))
269 else:
270 randomint = random.randint(1, 10)
271 await ctx.message.channel.send('The roll was: {}'.format(randomint))
272
273
274@bot.command(name='stop')
275async def stop(ctx, fightNum : int):
276 role = discord.utils.get(ctx.guild.roles, name='Underboss')
277 if role in ctx.author.roles:
278 global fightClub
279 global fightClub2
280 global fightClub3
281
282 if fightNum == 1:
283 fightClub = None
284 if fightNum == 2:
285 fightClub2 = None
286 if fightNum == 3:
287 fightClub3 = None
288
289 await ctx.message.channel.send('The fight has been stopped! This will not be recorded in your stats!')
290 else:
291 await ctx.message.delete()
292
293@bot.command(name='fight')
294async def fight(ctx, member : discord.Member = None, battle : int = None):
295 if member is not None and battle is not None:
296 chickenfucker = ctx.message.guild.get_member(259882923275190272)
297 await ctx.message.channel.send('{} has challanged {} to a fight! Let the battle begin!'.format(ctx.message.author.name, member.name))
298 await chickenfucker.send("{} has challanged {} to a fight. You are needed, master! This is occuring in `#battlegrounds-{}`".format(ctx.message.author.name, member.name, battle))
299 await member.send('{} has challanged you to a fight!'.format(ctx.message.author.name))
300
301 global fightClub
302 global fightClub2
303 global fightClub3
304
305 if fightClub == None and battle == 1:
306 fightClub = Fight(ctx.message.author, member)
307 fightClub.moves = 0
308 if fightClub2 == None and battle == 2:
309 fightClub2 = Fight(ctx.message.author, member)
310 fightClub2.moves = 0
311 if fightClub3 == None and battle == 3:
312 fightClub3 = Fight(ctx.message.author, member)
313 fightClub3.moves = 0
314 if fightClub != None and fightClub2 != None and fightClub3 != None:
315 ctx.message.channel.send('The fighting room specified is currently unavailible!')
316 else:
317 await ctx.message.channel.send("You have provided incorrect arugments")
318
319@bot.command(name="arrangefight")
320async def arrangefight(ctx, p1 : discord.Member = None, p2 : discord.Member = None, battle : int = None):
321 if p1 is not None and p2 is not None and battle is not None:
322 chickenfucker = ctx.message.guild.get_member(259882923275190272)
323 await ctx.message.channel.send('{} has challanged {} to a fight! Let the battle begin!'.format(p1.name, p2.name))
324 await chickenfucker.send("A fight has commenced between {} and {}, occuring in battlegrounds-{}`".format(p1.name, p2.name, str(battle)))
325 await p1.send('{} has challanged you to a fight!'.format(p1.name))
326 await p2.send('{} has challanged you to a fight!'.format(p2.name))
327 await ctx.message.delete()
328
329 global fightClub
330 global fightClub2
331 global fightClub3
332
333 if fightClub == None and battle == 1:
334 fightClub = Fight(p1, p2)
335 fightClub.moves = 0
336 if fightClub2 == None and battle == 2:
337 fightClub2 = Fight(p1, p2)
338 fightClub2.moves = 0
339 if fightClub3 == None and battle == 3:
340 fightClub3 = Fight(p1, p2)
341 fightClub3.moves = 0
342 if fightClub != None and fightClub2 != None and fightClub3 != None:
343 ctx.message.channel.send('The fighting room specified is currently unavailible!')
344 else:
345 await ctx.message.channel.send("The command is used as such: `*fights @<person a> @<person b> <battlegrounds number>")
346
347@bot.command(name="fightsilent")
348async def fightsilent(ctx, p1 : discord.Member = None, p2 : discord.Member = None, battle : int = None):
349 if p1 is not None and p2 is not None and battle is not None:
350 global fightClub
351 global fightClub2
352 global fightClub3
353
354 if fightClub == None and battle == 1:
355 fightClub = Fight(p1, p2)
356 fightClub.moves = 0
357 await ctx.message.delete()
358 if fightClub2 == None and battle == 2:
359 fightClub2 = Fight(p1, p2)
360 fightClub2.moves = 0
361 await ctx.message.delete()
362 if fightClub3 == None and battle == 3:
363 fightClub3 = Fight(p1, p2)
364 fightClub3.moves = 0
365 await ctx.message.delete()
366 if fightClub != None and fightClub2 != None and fightClub3 != None:
367 ctx.message.channel.send('The fighting room specified is currently unavailible!')
368 await ctx.message.delete()
369 else:
370 await ctx.message.channel.send("The command is used as such: `*fights @<person a> @<person b> <battlegrounds number>")
371
372@bot.command(name="info")
373async def info(ctx, battle :int = None):
374 if battle is None:
375 await ctx.message.channel.send("You did not provide a battlegrounds to check!")
376 else:
377 global fightClub
378 global fightClub2
379 global fightClub3
380
381 stuff = ctx.message.channel
382 if battle == 1 and fightClub is not None:
383 await stuff.send(f"{fightClub.p1.name} is currently fighting {fightClub.p2.name}")
384 elif battle == 2 and fightClub2 is not None:
385 await stuff.send(f"{fightClub2.p1.name} is currently fighting {fightClub2.p2.name}")
386 elif battle == 3 and fightClub3 is not None:
387 await stuff.send(f"{fightClub3.p1.name} is currently fighting {fightClub3.p2.name}")
388 else:
389 await stuff.send("Either no people are fighting or you provided an incorrect argument")
390
391@bot.command(name='purge')
392async def purge(ctx, amount: int):
393 role = discord.utils.get(ctx.guild.roles, name='Underboss')
394 if role in ctx.author.roles:
395 deleted = await ctx.channel.purge(limit=amount + 1)
396 await ctx.send(f'Deleted {len(deleted) - 1} messages')
397 else:
398 await ctx.message.delete()
399
400
401@bot.command(name="close")
402async def close(ctx):
403 if ctx.author.id == 202560656883449856:
404 await ctx.message.delete()
405 await bot.logout()
406 else:
407 await ctx.message.delete()
408
409bot.run('NjM1OTkwMjA1Mzg3NTA1Njk3.Xa5GGA.wQooavaGE1QLvQae6RSaL40nO94')