-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
253 lines (204 loc) · 9.12 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
from bot import *
from menus import *
from game import *
from config import TOKEN, GUILD_ID
# Declare intents
intents = discord.Intents.all()
# Instance of your Discord bot in your server
bot = BuckshotBot("!", intents, GUILD_ID)
@bot.tree.command()
async def challenge(interaction: discord.Interaction, player: discord.Member):
"""
Challenge another user in a gun fight with you
Parameters
-----------
player: discord.Member
The user that you want to challenge
"""
author = interaction.user # The user who used the command
# You cannot challenge yourself or a bot
if player.bot:
await interaction.response.send_message("You cannot challenge a bot!")
elif player.id == author.id:
await interaction.response.send_message(
"Do you really want to kys? :face_with_raised_eyebrow: I don't think so")
else: # Valid opponent
view = YesNoMenu(player) # Buttons
# Initialize the players and the game
p1 = Player(3, author)
p2 = Player(3, player)
game = Game(p1, p2)
await interaction.response.send_message(embed=game.challenge_display(), view=view) # The display message
timed_out = await view.wait() # Check to see if the user reaches timeout
# Disable all buttons
view.disable_buttons()
await interaction.edit_original_response(view=view)
if timed_out: # User ran out of time
await interaction.followup.send(f"**{player.display_name}** ran out of time to decide. "
f"The challenge is cancelled!")
else: # User chose a button
if view.value: # User chose Yes
await game.basic_game(interaction)
@bot.command(name="challenge")
async def prf_challenge(ctx: commands.Context, player: discord.Member):
"""
Challenge another user in a gun fight with you. This command is similar to /challenge
Parameters
-----------
player: discord.Member
The user that you want to challenge
"""
# This function use the exact same logic like the challenge() function
if player.bot:
await ctx.channel.send("You cannot challenge a bot!")
elif player.id == ctx.author.id:
await ctx.channel.send("Do you really want to kys? :face_with_raised_eyebrow: I don't think so")
else: # Valid opponent
view = YesNoMenu(player) # Buttons
# Initialize the players and the game
p1 = Player(3, ctx.author)
p2 = Player(3, player)
game = Game(p1, p2)
display_msg = await ctx.channel.send(embed=game.challenge_display(), view=view) # The display message
timed_out = await view.wait() # Check to see if the user reaches timeout
# Disable all buttons
view.disable_buttons()
await display_msg.edit(view=view)
if timed_out: # User ran out of time
await ctx.channel.send(f"**{player.display_name}** ran out of time to decide. The challenge is cancelled!")
else: # User chose a button
if view.value: # User chose Yes
await game.basic_game(ctx)
# Item information for the 2 functions below
item = {
"Expired Medicine": "Heal 1 - 2 :heart: **LIFE** or lose 1 :heart: **LIFE** but not more than your "
"initial :heart: **LIFE**\n",
"Inverter": "Switch the color of all bullets\n",
"Cigarette": "Heal 1 :heart: **LIFE** but not more than your initial :heart: **LIFE**\n",
"Burner Phone": "Reveal the color of a random bullet\n",
"Adrenaline": "Steal an item from your opponent\n",
"Magnifying Glass": "Reveal the color of the current bullet\n",
"Beer": "Eject the current bullet\n",
"Hand Saw": "Double the damage of the next shot\n",
"Handcuffs": "Force your opponent to skip their next turn"
}
@bot.tree.command()
async def item_info(interaction: discord.Interaction):
"""Show information about all items available in the game"""
description = ""
for name, usage in item.items():
description += f"**{name}**: {usage}\n"
await interaction.response.send_message(embed=discord.Embed(
colour=discord.Colour.purple(),
title="Item information",
description=description
))
@bot.command(name="item_info")
async def prf_item_info(ctx: commands.Context):
"""Show information about all items available in the game"""
description = ""
for name, usage in item.items():
description += f"**{name}**: {usage}\n"
await ctx.channel.send(embed=discord.Embed(
colour=discord.Colour.purple(),
title="Item information",
description=description
))
@bot.tree.command()
async def advanced_challenge(interaction: discord.Interaction, player: discord.Member):
"""
Challenge another user in a gun fight with you but with support items
Parameters
-----------
player: discord.Member
The user that you want to challenge
"""
author = interaction.user # The user who used the command
# You cannot challenge yourself or a bot
if player.bot:
await interaction.response.send_message("You cannot challenge a bot!")
elif player.id == author.id:
await interaction.response.send_message(
"Do you really want to kys? :face_with_raised_eyebrow: I don't think so")
else: # Valid opponent
view = YesNoMenu(player) # Buttons
# Initialize the players and the game
hp = random.randint(3, 6)
p1 = Player(hp, author)
p2 = Player(hp, player)
game = Game(p1, p2)
await interaction.response.send_message(embed=game.challenge_display(), view=view) # The display message
timed_out = await view.wait() # Check to see if the user reaches timeout
# Disable all buttons
view.disable_buttons()
await interaction.edit_original_response(view=view)
if timed_out: # User ran out of time
await interaction.followup.send(f"**{player.display_name}** ran out of time to decide. "
f"The challenge is cancelled!")
else: # User chose a button
if view.value: # User chose Yes
await game.basic_game(interaction, True)
@bot.command(name="advanced_challenge")
async def prf_advanced_challenge(ctx: commands.Context, player: discord.Member):
"""
Challenge another user in a gun fight with you but with support items. This command is similar to
/advanced_challenge
Parameters
-----------
player: discord.Member
The user that you want to challenge
"""
# This function use the exact same logic like the challenge() function
if player.bot:
await ctx.channel.send("You cannot challenge a bot!")
elif player.id == ctx.author.id:
await ctx.channel.send("Do you really want to kys? :face_with_raised_eyebrow: I don't think so")
else: # Valid opponent
view = YesNoMenu(player) # Buttons
# Initialize the players and the game
hp = random.randint(3, 6)
p1 = Player(hp, ctx.author)
p2 = Player(hp, player)
game = Game(p1, p2)
display_msg = await ctx.channel.send(embed=game.challenge_display(), view=view) # The display message
timed_out = await view.wait() # Check to see if the user reaches timeout
# Disable all buttons
view.disable_buttons()
await display_msg.edit(view=view)
if timed_out: # User ran out of time
await ctx.channel.send(f"**{player.display_name}** ran out of time to decide. The challenge is cancelled!")
else: # User chose a button
if view.value: # User chose Yes
await game.basic_game(ctx, True)
rule = """
- Two players engage in a gunfight (with support items available in advanced mode).\n
- Details about support items can be found using `/item_info`.\n
- New items are randomly added to each player every time the gun is reloaded.\n
- Players take turns using items and shooting bullets.\n
- Each player can use multiple items before shooting a bullet.\n
- Bullets are displayed at the beginning and randomized right after (and reloaded when needed).\n
- There are two types of bullets: :red_square: **RED** and :blue_square: **BLUE**.\n
- Each player can decide to shoot themselves or their opponent.\n
- A player shot with a :blue_square: **BLUE** bullet will not lose any :heart: **LIFE**.\n
- A player shot with a :red_square: **RED** bullet will lose 1 :heart: **LIFE**.\n
- The first player to reach 0 :heart: **LIFE** loses the duel.\n
- If a player shoots themselves with a :blue_square: **BLUE** bullet, their turn will continue.
"""
@bot.tree.command()
async def rules(interaction: discord.Interaction):
"""Rules of the game"""
await interaction.response.send_message(embed=discord.Embed(
colour=discord.Colour.purple(),
title="Rules",
description=rule
))
@bot.command(name="rules")
async def prf_rules(ctx: commands.Context):
"""Rules of the game"""
await ctx.channel.send(embed=discord.Embed(
colour=discord.Colour.purple(),
title="Rules",
description=rule
))
# Run the bot
bot.run(TOKEN)