-
Notifications
You must be signed in to change notification settings - Fork 1
/
pybot.py
159 lines (137 loc) · 6.65 KB
/
pybot.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
import discord
from discord import app_commands
from discord.ext import commands
from discord.utils import get
#from config import TOKEN
import os
import html
import requests
import re
import asyncio
import random
import time
client = commands.AutoShardedBot(shards=2, command_prefix = '-', intents=discord.Intents.default())
@client.event
async def on_ready():
print('Bot Activated!\n')
print('------------------------------\n')
try:
synced = await client.tree.sync()
print(f"Synced {len(synced)} commands")
except Exception as e:
print(e)
while True:
act = f'debates in {len(client.guilds)} servers'
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=act))
await asyncio.sleep(1800)
@client.tree.command(name="ping",description="Checks response time between client and Hear Hear! bot.")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message(f"Pinged in {round(client.latency*1000)} ms.")
@client.tree.command(name="commands",description="Lists commands for the Hear Hear bot.")
async def commands(interaction: discord.Interaction):
embed = discord.Embed()
embed.title = "List of Commands for the Hear! Hear! Bot"
embed.set_image(url="https://i.imgur.com/7Lw4CRt.gif")
embed.description = f"""
`/ping`
Checks response time between client and Hear Hear! bot.
`/commands`
Displays list of commands.
`/coinflip`
Randomly chooses between heads and tails. Useful for vetoes.
`/getmotion`
Displays a random motion from the hellomotions motion bank.
`/time`
Times a speech with format *XmYs*, e.g. *7m*, *5m30s*, *30s*.
"""
#embed.set_footer(text="Message <@704206757681037362> or <@696777012110688296> for technical help.",icon_url="https://i.imgur.com/RaQy5so.png")
await interaction.response.send_message(embed=embed)
@client.tree.command(name="getmotion",description="Displays a random motion from the hellomotions motion bank.")
async def getmotion(interaction: discord.Interaction):
req = requests.get("https://hellomotions.com/random-motion")
body = req.text.split("<b>")
motion = html.unescape((body[1].split("</b"))[0])
await interaction.response.send_message(f"{motion}")
@client.tree.command(name="coinflip",description="Chooses between heads and tails, useful for vetoes")
async def coinflip(interaction: discord.Interaction):
coin = ["Head", "Tail"]
await interaction.response.send_message(f"The coin shows **{random.choice(coin)}**!")
class Timer(discord.ui.View):
def __init__(self,mins,secs):
super().__init__()
self.mins = mins
self.secs = secs
self.paused = False
self.stopped = False
self.time1 = int(mins)*60 + int(secs)
self.time2 = self.time1
self.time3 = 0
self.buttonPause = discord.ui.Button(label="Pause ✋", style=discord.ButtonStyle.grey)
self.buttonStop = discord.ui.Button(label="Stop Timer 🛑", style=discord.ButtonStyle.blurple)
async def time(self, interaction):
msg = interaction.message
if interaction.response.is_done():
await msg.edit(view=self)
else:
await interaction.response.edit_message(view=self)
n = float(1)
while self.time2 >= 0 and not self.paused and not self.stopped:
await msg.edit(content=f"⏳ **Timer** `{str(int(self.time2/60)).zfill(2)} : {str(self.time2%60).zfill(2)}`")
j = self.time2%5
if j:
self.time2 -= j
self.time3 += j
await msg.edit(content=f"⏳ **Timer** `{str(int(self.time2/60)).zfill(2)} : {str(self.time2%60).zfill(2)}`")
await asyncio.sleep(4+float(n))
self.time2 -= 5
self.time3 += 5
if self.time3 == 60:
await interaction.channel.send(f"\n\n🟢 **1 minute done!** {interaction.user.mention}")
if self.time2 == 60:
await interaction.channel.send(f"\n\n🟠 **1 minute left!** {interaction.user.mention}")
if self.time2 == 0:
self.buttonPause.disabled = True
self.buttonStop.disabled = True
await msg.edit(content="Timer stopped! Use `/time` to start a new timer.",view=self)
await interaction.channel.send(f"\n\n🔴 **Time's up!** {interaction.user.mention}")
@discord.ui.button(label="Start Timer ⏱️", style=discord.ButtonStyle.green)
async def buttonStart(self, interaction: discord.Interaction, button: discord.ui.Button):
async def pause(interaction: discord.Interaction):
self.buttonStop.disabled = not self.buttonStop.disabled
self.paused = not self.paused
if self.paused:
self.buttonPause.label = "Resume 👍"
if interaction.response.is_done():
await interaction.message.edit(content=f"⏸️ **PAUSED** `{str(int(self.time2/60)).zfill(2)} : {str(self.time2%60).zfill(2)}`",view=self)
else:
await interaction.response.edit_message(content=f"⏸️ **PAUSED** `{str(int(self.time2/60)).zfill(2)} : {str(self.time2%60).zfill(2)}`",view=self)
if not self.paused:
self.buttonPause.label = "Pause ✋"
await self.time(interaction)
async def stop(interaction: discord.Interaction):
self.buttonPause.disabled = True
self.buttonStop.disabled = True
self.stopped = True
await interaction.response.edit_message(content="Timer stopped! Use `/time` to start a new timer.",view=self)
self.buttonPause.callback = pause
self.buttonStop.callback = stop
button.disabled = True
self.add_item(self.buttonPause)
self.add_item(self.buttonStop)
await self.time(interaction)
@client.tree.command(name="time", description="Times a debate speech.")
@app_commands.describe(time="Specify time using format XmYs or Ym, where X=minutes and Y=seconds e.g. 7m15s or 7m")
async def timer(interaction: discord.Interaction, time: str):
pattern = re.compile("^([0-9]{1,2}m[0-9]{1,2}s)|([0-9]{1,2}m)|([0-9]{1,2}s)$")
if not re.match(pattern, time):
await interaction.response.send_message("Invalid syntax! Please use the format `XmYs`, e.g. `7m15s`.")
return
time = time.split("m")
if len(time)==2:
mins = time[0].zfill(2)
secs = time[1][:-1].zfill(2)
else:
mins = "00"
secs = time[0][:-1].zfill(2)
await interaction.response.send_message(f"⏳ **Timer** `{mins} : {secs}`", view=Timer(mins,secs))
client.run(os.environ['TOKEN'])