-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm.py
69 lines (57 loc) · 2.77 KB
/
confirm.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
import discord
from discord import ui
from utils import GIRContext
from utils.framework import gatekeeper
class Confirm(ui.View):
def __init__(self, ctx: GIRContext, true_response = None, false_response = None):
super().__init__(timeout=20)
self.ctx = ctx
self.value = None
self.true_response = true_response
self.false_response = false_response
async def on_timeout(self) -> None:
await self.ctx.send_warning("Timed out.")
return await super().on_timeout()
async def interaction_check(self, interaction: discord.Interaction) -> bool:
return interaction.user == self.ctx.author
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@ui.button(label='Yes', style=discord.ButtonStyle.success)
async def confirm(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
self.value = True
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@ui.button(label='No', style=discord.ButtonStyle.grey)
async def cancel(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
if self.false_response is not None:
await self.ctx.send_warning(description=self.false_response)
self.value = False
self.stop()
class SecondStaffConfirm(ui.View):
def __init__(self, ctx: GIRContext, og_mod: discord.Member):
super().__init__(timeout=20)
self.ctx = ctx
self.value = None
self.og_mod = og_mod
async def on_timeout(self) -> None:
await self.ctx.send_warning("Timed out.")
return await super().on_timeout()
async def interaction_check(self, interaction: discord.Interaction) -> bool:
return interaction.user.id != self.og_mod.id and gatekeeper.has(self.ctx.guild, interaction.user, 5)
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@ui.button(label='Yes', style=discord.ButtonStyle.success)
async def confirm(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
self.value = True
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@ui.button(label='No', style=discord.ButtonStyle.grey)
async def cancel(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
self.value = False
self.stop()