-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
107 lines (97 loc) · 3.81 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
import asyncio
import random
import interactions
import os
from interactions import slash_command, SlashContext, listen, Intents, slash_option, OptionType, SlashCommandChoice
from dotenv import load_dotenv
intents = Intents.ALL
client = interactions.Client(intents=intents,status=interactions.Status.ONLINE,activity=interactions.Activity(name="Yggdrasil sucks", type=interactions.ActivityType.GAME))
userphone = True
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
@interactions.listen()
async def on_startup():
print("Bot is ready!")
@slash_command(name="my_command", description="My first command :)")
async def firstcommand(ctx: SlashContext):
await ctx.send("Hello World")
@slash_command(name="randomnum", description="Generates a random number from a specified range")
@slash_option(
name="minnum",
description="Minimum number",
required=True,
opt_type=OptionType.INTEGER,
min_value=0
)
@slash_option(
name="maxnum",
description="Maximun number",
required=True,
opt_type=OptionType.INTEGER,
)
async def randomnum(ctx: SlashContext, minnum: int, maxnum: int):
if minnum < 0:
await ctx.send("Error: Minimun number cannot be less than 0")
return
if maxnum < 0:
await ctx.send("Error: Maximun number cannot be less than 0")
return
elif maxnum == minnum:
await ctx.send(f"Your not so random number is: {minnum}")
return
else:
randomout = random.randrange(minnum, maxnum)
await ctx.send(f"Your random number is: {randomout}")
@slash_command(name="toggleuserphone", description="Toggle the userphone timer")
@slash_option(
name="toggle",
description="Toggle the userphone timer On or Off",
required=True,
opt_type=OptionType.BOOLEAN,
choices=[
SlashCommandChoice(name="On", value=True),
SlashCommandChoice(name="Off", value=False)
]
)
async def toggleuserphone(ctx: SlashContext, toggle: bool):
global userphone
if toggle == True:
userphone = True
await ctx.send("Userphone timer is now turned On.")
elif toggle == False:
userphone = False
await ctx.send("Userphone timer is now turned Off.")
@slash_command(name="ping", description="Pong!")
async def ping(ctx: SlashContext):
await ctx.send('Pong! {0}'.format(round(client.latency, 3)))
@slash_command(name="shutdown", description="Shutdown the bot.")
async def shutdown(ctx: SlashContext):
if ctx.user.id == 824240215577067541:
await ctx.send("Shutting down...")
await client.stop()
else:
await ctx.send("You do not have permision to do this.")
@listen()
async def on_message_create(event):
if userphone == False:
return
else:
if "You hung up the userphone" in event.message.content:
emoji = '\N{HOURGLASS WITH FLOWING SAND}'
await event.message.add_reaction(emoji)
await asyncio.sleep(20)
await event.message.reply('Ready to `--userphone` again!', mention_author=True)
await event.message.remove_reaction(emoji,client.user)
if "The other party hung up the userphone" in event.message.content:
emoji = '\N{HOURGLASS WITH FLOWING SAND}'
await event.message.add_reaction(emoji)
await asyncio.sleep(5)
await event.message.reply('Ready to `--userphone` again!', mention_author=True)
await event.message.remove_reaction(emoji,client.user)
if "The userphone connection has been lost" in event.message.content:
emoji = '\N{HOURGLASS WITH FLOWING SAND}'
await event.message.add_reaction(emoji)
await asyncio.sleep(20)
await event.message.reply('Ready to `--userphone` again!', mention_author=True)
await event.message.remove_reaction(emoji,client.user)
client.start(token)