-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
539 lines (433 loc) · 18.1 KB
/
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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
import discord
import json
import random
import asyncio
from discord.ext import commands
from discord.ui import Button, View
description = 'bot made by F1L1P.\n'
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
class CustomHelp(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
for page in self.paginator.pages:
emby = discord.Embed(description=page)
await destination.send(embed=emby)
bot = commands.Bot(command_prefix=commands.when_mentioned_or("."), help_command=CustomHelp(), description=description, intents=intents,
activity=discord.Activity(type=discord.ActivityType.watching, name=".help", status=discord.Status.dnd))
token = open("token.txt", "r")
token = token.read()
gamestarted = False
@bot.event
async def on_command_error(ctx, error):
#await ctx.message.add_reaction(redX)
msg = await ctx.reply(f"❌ `{error}`")
await ctx.message.delete()
await asyncio.sleep(0.5)
await msg.delete()
# print(f"ERROR: {error}")
raise error
@bot.event
async def on_ready():
await bot.add_cog(Admin(bot))
await bot.add_cog(TankTactics(bot))
await bot.add_cog(Movement(bot))
await bot.add_cog(Experimental(bot))
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
member_count = 0
guild_string = ""
for g in bot.guilds:
guild_string += f"{g.name} - {g.id} - Members: {g.member_count}\n"
member_count += g.member_count
print(
f"Bot '{bot.user.name}' has connected, active on {len(bot.guilds)} guilds:\n{guild_string}")
def inrange(x, y, tarx, tary, range):
if(x-range <= tarx <= x+range):
if(y-range <= tary <= y+range):
return True
return False
def getList(dict):
return dict.keys()
def move(x, y, author):
if gamestarted == False:
return
femoji = ""
fcordinates = []
with open("list.json", "r+") as f:
json_data = json.loads(f.read())
femoji = json_data[str(author)]["emoji"]
fcordinates = json_data[str(author)]["cordinates"]
ranges = json_data[str(author)]["range"]
lives = json_data[str(author)]["life"]
energ = json_data[str(author)]["energy"]
if(energ > 0):
json_data[str(author)] = {"emoji": femoji, "cordinates": [
fcordinates[0]+x, fcordinates[1]+y], "range": ranges, "life": lives, "energy": energ-1}
with open("list.json", "w") as f:
new_json = json.dumps(json_data, indent=4)
f.write(new_json)
def fillscreen():
with open("list.json", "r") as f:
json_data = json.loads(f.read())
if gamestarted == False:
return "Game Not Started"
replymessage = ""
for y in range(14):
for x in range(14):
replymessage += "⬛"
for player in json_data.keys():
if(player == ''):
break
if(json_data[player]["cordinates"][0] == x and json_data[player]["cordinates"][1] == y):
replymessage = replymessage[:-1]
replymessage += json_data[player]["emoji"]
replymessage += "\n"
return replymessage
class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.has_permissions(kick_members=True)
async def purge(self, ctx, amount: int):
"""Clears recent messages"""
#await ctx.message.add_reaction(greenTick)
await ctx.message.delete()
deleted = await ctx.channel.purge(limit=amount)
await ctx.channel.send(f'Deleted {len(deleted)} message(s)', delete_after=5)
@commands.command()
@commands.has_permissions(kick_members=True)
async def nS(self, ctx):
"""Creates a new screen"""
screen = await ctx.send(fillscreen())
f = open("viewmessage.txt", "w+")
f.write(str(screen.id))
f.close()
await ctx.message.delete()
@commands.command()
@commands.has_permissions(kick_members=True)
async def rS(self, ctx):
"""refreshes screen"""
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
@commands.has_permissions(kick_members=True)
async def restart(self, ctx):
with open("list.json", "w") as f:
f.write("{}")
global gamestarted
gamestarted = False
await ctx.message.delete()
@commands.command()
@commands.has_permissions(kick_members=True)
async def start(self, ctx):
with open("list.json", "r") as f:
json_data = json.loads(f.read())
if len(json_data.keys()) > 1:
global gamestarted
gamestarted = True
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
return
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content="Need More Then 1 player")
await ctx.message.delete()
class TankTactics(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def stats(self, ctx, *, member: discord.Member = None):
global gamestarted
if gamestarted == 0:
await ctx.message.delete()
return
if member is None:
member = ctx.author
with open("list.json", "r") as f:
json_data = json.loads(f.read())
energy = json_data[str(member.id)]["energy"]
life = json_data[str(member.id)]["life"]
emoji = json_data[str(member.id)]["emoji"]
msg = await ctx.send(f"{member.name} {emoji} has {energy} energy {life} lifes")
await ctx.message.delete()
await asyncio.sleep(2)
await msg.delete()
@commands.command()
async def shoot(self, ctx, *, member: discord.Member = None):
"""shoot"""
if member is None:
return
with open("list.json", "r") as f:
json_data = json.loads(f.read())
playerrange = json_data[str(ctx.author.id)]["range"]
playerx = json_data[str(ctx.author.id)]["cordinates"][0]
playery = json_data[str(ctx.author.id)]["cordinates"][1]
tarx = json_data[str(member.id)]["cordinates"][0]
tary = json_data[str(member.id)]["cordinates"][1]
if(str(member.id) in json_data):
if(inrange(playerx, playery, tarx, tary, playerrange)):
json_data[str(member.id)]["life"] -= 1
json_data[str(ctx.author.id)]["energy"] -= 1
if (json_data[str(member.id)]["life"] == 0):
json_data.pop(str(member.id))
with open("list.json", "w") as f:
new_json = json.dumps(json_data, indent=4)
f.write(new_json)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await ctx.message.add_reaction("✅")
if len(json_data.keys()) <= 1:
with open("list.json", "w") as f:
f.write("{}")
await msg.edit(content=f"{ctx.author.name} Won")
global gamestarted
gamestarted = False
await asyncio.sleep(0.5)
await ctx.message.delete()
return
await msg.edit(content=fillscreen())
await asyncio.sleep(0.5)
await ctx.message.delete()
return
await ctx.message.add_reaction("❌")
await asyncio.sleep(0.5)
await ctx.message.delete()
@commands.command()
async def give(self, ctx, member: discord.Member = None, energy: int = None):
"""give energy points"""
if gamestarted == 0:
await ctx.message.delete()
return
if member is None:
return
if energy is None:
energy = 1
with open("list.json", "r") as f:
json_data = json.loads(f.read())
playerrange = json_data[str(ctx.author.id)]["range"]
playerx = json_data[str(ctx.author.id)]["cordinates"][0]
playery = json_data[str(ctx.author.id)]["cordinates"][1]
tarx = json_data[str(member.id)]["cordinates"][0]
tary = json_data[str(member.id)]["cordinates"][1]
if inrange(playerx, playery, tarx, tary, playerrange):
print(f"Gave {energy} to {member.name}")
json_data[str(ctx.author.id)]["energy"] -= energy
json_data[str(member.id)]["energy"] += energy
with open("list.json", "w") as f:
new_json = json.dumps(json_data, indent=4)
f.write(new_json)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.add_reaction("✅")
await asyncio.sleep(0.5)
await ctx.message.delete()
return
await ctx.message.add_reaction("❌")
await asyncio.sleep(0.5)
await ctx.message.delete()
@commands.command()
async def join(self, ctx, emoji: str = None):
"""join to game"""
if (emoji is None):
emoji = "📦"
with open("list.json", "r") as f:
json_data = json.loads(f.read())
if str(ctx.author.id) in json_data.keys():
await ctx.message.add_reaction("❌")
await asyncio.sleep(0.5)
await ctx.message.delete()
return
json_data[ctx.author.id] = {"emoji": emoji, "cordinates": [
random.randrange(12), random.randrange(12)], "range": 2, "life": 3, "energy": 3}
new_json = json.dumps(json_data, indent=4)
with open("list.json", "w") as f:
new_json = json.dumps(json_data, indent=4)
f.write(new_json)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
class Movement(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def left(self, ctx):
move(-1, 0, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def right(self, ctx):
move(1, 0, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def up(self, ctx):
move(0, -1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def down(self, ctx):
move(0, 1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def upleft(self, ctx):
move(-1, -1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def upright(self, ctx):
move(1, -1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def downleft(self, ctx):
move(-1, 1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
@commands.command()
async def downright(self, ctx):
move(1, 1, ctx.author.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
await ctx.message.delete()
class Experimental(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.has_permissions(kick_members=True)
async def bC(self, ctx):
"""creates button"""
if gamestarted == 0:
await ctx.message.delete()
return
leftb = Button(label="", style=discord.ButtonStyle.grey, emoji="⬅️")
rightb = Button(label="", style=discord.ButtonStyle.grey, emoji="➡️")
upb = Button(label="", style=discord.ButtonStyle.grey, emoji="⬆️")
downb = Button(label="", style=discord.ButtonStyle.grey, emoji="⬇️")
upleftb = Button(label="", style=discord.ButtonStyle.grey, emoji="↖️")
uprightb = Button(label="", style=discord.ButtonStyle.grey, emoji="↗️")
downleftb = Button(
label="", style=discord.ButtonStyle.grey, emoji="↙️")
downrightb = Button(
label="", style=discord.ButtonStyle.grey, emoji="↘️")
button = Button(label="", style=discord.ButtonStyle.grey, emoji="🟦")
async def left(interaction):
move(-1, 0, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def right(interaction):
move(1, 0, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def up(interaction):
move(0, -1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def down(interaction):
move(0, 1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def upleft(interaction):
move(-1, -1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def upright(interaction):
move(1, -1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def downleft(interaction):
move(-1, 1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
async def downright(interaction):
move(1, 1, interaction.user.id)
with open("viewmessage.txt", "r+") as f:
channel = bot.get_channel(ctx.channel.id)
msg = await channel.fetch_message(f.read())
await msg.edit(content=fillscreen())
# await interaction.response.send_message('left')
leftb.callback = left
rightb.callback = right
upb.callback = up
downb.callback = down
upleftb.callback = upleft
uprightb.callback = upright
downrightb.callback = downright
downleftb.callback = downleft
upview = View()
midview = View()
downview = View()
upview.add_item(upleftb)
upview.add_item(upb)
upview.add_item(uprightb)
midview.add_item(leftb)
midview.add_item(button)
midview.add_item(rightb)
downview.add_item(downleftb)
downview.add_item(downb)
downview.add_item(downrightb)
await ctx.send("", view=upview)
await ctx.send("", view=midview)
await ctx.send("", view=downview)
await ctx.message.delete()
intents = discord.Intents.default()
intents.message_content = True
if __name__ == "__main__":
bot.run(token)