-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.py
128 lines (106 loc) · 4.17 KB
/
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
import discord
from discord.ext import commands
from discord.commands import option
from utils import *
from config import Config
bot = HungerGamesBot(Config())
@bot.event
async def on_application_command_error(ctx, error):
if isinstance(error, discord.errors.ApplicationCommandInvokeError):
error = error.original
if isinstance(error, HungerGamesError):
await ctx.reply(error)
elif isinstance(error, commands.MissingPermissions):
await ctx.reply(error)
elif type(error) in (commands.CheckFailure, discord.commands.errors.CheckFailure):
pass
else:
await ctx.reply(f'An unknown error occurred: {error}')
raise error
@bot.slash_command()
@option('role', description="The Contestant Role", required=False)
@commands.has_permissions(administrator=True)
async def setup(ctx, role: discord.Role):
"""
Setup a new instance of the Hunger Games.
"""
role = role or discord.utils.get(ctx.guild.roles, name='Contestant')
await bot.create_game(role)
await ctx.respond("I have created an instance of the Hunger games for your server.\nPeople can now `/volunteer` or you can add them using `/add tribute`")
@bot.slash_command()
@game_exists()
async def volunteer(ctx):
"""
Volunteer as a tribute for the Hunger Games.
"""
game = bot.get_game(ctx)
if game.running:
return await ctx.reply(f"A game is already running in {ctx.channel.mention}, please wait for it to finish before registering.")
result = await game.add_contestant(ctx.author)
if result:
await ctx.respond("You have volunteered as tribute. May the odds be ever in your favour.")
else:
await ctx.reply("You are already selected as a tribute.")
@bot.slash_command()
@option('tribute', description="The member to select as a Tribute")
@game_exists()
@commands.has_permissions(administrator=True)
async def add(ctx, tribute: discord.Member):
"""
Select a tribute for the Hunger Games.
"""
game = bot.get_game(ctx)
if game.running:
return await ctx.reply(f"A game is already running in {ctx.channel.mention}, please wait for it to finish before trying to add a tribute.")
result = await game.add_contestant(tribute)
if result:
await ctx.respond(f"{tribute.mention} has been selected as tribute. May the odds be ever in their favour.")
else:
await ctx.reply(f"{tribute.mention} is already selected as a tribute.")
@bot.slash_command()
@game_exists()
@commands.has_permissions(administrator=True)
async def start(ctx):
"""Starts the Hunger Games in the channel the command is run."""
game = bot.get_game(ctx)
if game.running:
return await ctx.reply(f"The game is already running in {ctx.channel.mention}, please wait for it to finish before trying to start it.")
await game.run(ctx)
@bot.slash_command()
@is_registered()
async def inventory(ctx):
await ctx.reply('Your inventory is empty')
@bot.slash_command()
async def map(ctx):
"""
Shows the map of the Hunger Games Arena.
"""
await ctx.respond("Here's the map of the Hunger Games Arena. \nSection V is the Cornucopia. Section I, III, VII and IX are high risk high reward sections.")
await ctx.send(file=discord.File('map.png'))
@bot.slash_command()
@is_registered()
async def stats(ctx):
"""
Shows your stats if you are a tribute.
"""
embed = bot.get_game(ctx).create_stats_embed(ctx.author)
await ctx.reply(embed=embed)
@bot.command()
async def source(ctx):
await ctx.send('https://github.com/CodeWithSwastik/HungerGamesBot')
tribute = bot.create_group('tribute', 'Commands related to Tributes')
@tribute.command(name='list')
@game_exists()
async def list_(ctx):
"""
Lists all tributes
"""
embed = bot.get_game(ctx).create_tributes_embed()
await ctx.reply(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def test(ctx):
game = await bot.create_game(discord.utils.get(ctx.guild.roles, name='Contestant'))
ctx.respond = ctx.send
await game.add_contestant(ctx.author)
await game.run(ctx)