Skip to content

Commit e1073f7

Browse files
committed
significant progress on help channels at least
1 parent 315d161 commit e1073f7

File tree

19 files changed

+421
-402
lines changed

19 files changed

+421
-402
lines changed

index.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,62 @@
1717
)
1818

1919
# Logs
20-
# from modules.logs.listeners import LogsListeners
21-
# bot.add_cog(LogsListeners(bot))
20+
from modules.logs.listeners import LogsListeners
21+
bot.add_cog(LogsListeners(bot))
2222

2323
# Moderation
24-
# from modules.moderation.listeners import ModerationListeners
25-
# bot.add_cog(ModerationListeners(bot))
26-
# from modules.moderation.commands.mod import ModCommand
27-
# bot.add_cog(ModCommand(bot))
28-
# from modules.moderation.message_commands.moderate import ModerateCommand
29-
# bot.add_cog(ModerateCommand(bot))
30-
# from modules.moderation.message_commands.report import ReportCommand
31-
# bot.add_cog(ReportCommand(bot))
24+
from modules.moderation.listeners import ModerationListeners
25+
bot.add_cog(ModerationListeners(bot))
26+
from modules.moderation.commands.mod import ModCommand
27+
bot.add_cog(ModCommand(bot))
28+
from modules.moderation.message_commands.moderate import ModerateCommand
29+
bot.add_cog(ModerateCommand(bot))
30+
from modules.moderation.message_commands.report import ReportCommand
31+
bot.add_cog(ReportCommand(bot))
3232

3333
# Help Channels
34-
# from modules.help_channels.listeners import HelpChannelListeners
35-
# bot.add_cog(HelpChannelListeners(bot))
36-
# from modules.help_channels.commands.resolve import ResolveCommand
37-
# bot.add_cog(ResolveCommand(bot))
38-
# from modules.help_channels.commands.summon import SummonCommand
39-
# bot.add_cog(SummonCommand(bot))
40-
# from modules.help_channels.commands.top import TopCommand
41-
# bot.add_cog(TopCommand(bot))
42-
# from modules.help_channels.message_commands.redirect import RedirectCommand
43-
# bot.add_cog(RedirectCommand(bot))
44-
# from modules.help_channels.message_commands.remind import RemindCommand
45-
# bot.add_cog(RemindCommand(bot))
34+
from modules.help_channels.listeners import HelpChannelListeners
35+
bot.add_cog(HelpChannelListeners(bot))
36+
from modules.help_channels.commands.resolve import ResolveCommand
37+
bot.add_cog(ResolveCommand(bot))
38+
from modules.help_channels.commands.summon import SummonCommand
39+
bot.add_cog(SummonCommand(bot))
40+
from modules.help_channels.commands.top import TopCommand
41+
bot.add_cog(TopCommand(bot))
42+
from modules.help_channels.message_commands.redirect import RedirectCommand
43+
bot.add_cog(RedirectCommand(bot))
44+
from modules.help_channels.message_commands.remind import RemindCommand
45+
bot.add_cog(RemindCommand(bot))
4646

4747
# Utilities
48-
# from modules.utilities.commands.members import MembersCommand
49-
# bot.add_cog(MembersCommand(bot))
50-
# from modules.utilities.commands.help import HelpCommand
51-
# bot.add_cog(HelpCommand(bot))
52-
# from modules.utilities.commands.icon import IconCommand
53-
# bot.add_cog(IconCommand(bot))
54-
# from modules.utilities.message_commands.view import ViewFileCommand
55-
# bot.add_cog(ViewFileCommand(bot))
48+
from modules.utilities.commands.members import MembersCommand
49+
bot.add_cog(MembersCommand(bot))
50+
from modules.utilities.commands.help import HelpCommand
51+
bot.add_cog(HelpCommand(bot))
52+
from modules.utilities.commands.icon import IconCommand
53+
bot.add_cog(IconCommand(bot))
54+
from modules.utilities.message_commands.view import ViewFileCommand
55+
bot.add_cog(ViewFileCommand(bot))
5656

5757
# Fun
58-
# from modules.fun.listeners import FunListeners
59-
# bot.add_cog(FunListeners(bot))
60-
# from modules.fun.commands.suspension import SuspensionRailwayCommand
61-
# bot.add_cog(SuspensionRailwayCommand(bot))
62-
# from modules.fun.commands.uwu import UwuCommand
63-
# bot.add_cog(UwuCommand(bot))
58+
from modules.fun.listeners import FunListeners
59+
bot.add_cog(FunListeners(bot))
60+
from modules.fun.commands.suspension import SuspensionRailwayCommand
61+
bot.add_cog(SuspensionRailwayCommand(bot))
62+
from modules.fun.commands.uwu import UwuCommand
63+
bot.add_cog(UwuCommand(bot))
6464

6565
# Welcome
66-
# from modules.welcome.listeners import WelcomeListeners
67-
# bot.add_cog(WelcomeListeners(bot))
66+
from modules.welcome.listeners import WelcomeListeners
67+
bot.add_cog(WelcomeListeners(bot))
6868

6969
# Events
70-
# from modules.events.button_click import OnButtonClick
71-
# bot.add_cog(OnButtonClick(bot))
70+
from modules.events.button_click import OnButtonClick
71+
bot.add_cog(OnButtonClick(bot))
7272

7373
# Stats
74-
from modules.stats.commands.stats import StatsCommand
75-
bot.add_cog(StatsCommand(bot))
74+
# from modules.stats.commands.stats import StatsCommand
75+
# bot.add_cog(StatsCommand(bot))
7676
# from modules.stats.commands.stats_admin import StatsAdminCommand
7777
# bot.add_cog(StatsAdminCommand(bot))
7878

@@ -138,7 +138,7 @@ async def on_ready():
138138
Log.info("Bot has started!")
139139

140140
await autoclose_loop.start()
141-
await schedule_qotd(bot)
141+
# await schedule_qotd(bot)
142142

143143
# Run bot
144144
bot.run(TOKEN)

modules/events/button_click.py

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import discord
22
from discord.ext import commands
33
import variables
4-
import datetime
54
import utils.log as Log
6-
from utils.stats import update
75
from utils.res_thread import resolve_thread
86

9-
107
class OnButtonClick(commands.Cog):
118
def __init__(self, bot: commands.Bot):
129
self.bot = bot
1310

14-
@commands.Cog.listener()
15-
async def on_button_click(self, inter: discord.MessageInteraction):
11+
@discord.Cog.listener("on_button_click")
12+
async def on_button_click(self, inter: discord.ApplicationContext):
1613
if inter.component.custom_id == "resolve_question_button":
1714
role = inter.guild.get_role(variables.helper)
1815
if (inter.channel.owner_id == inter.user.id) or (role in inter.user.roles):
@@ -29,73 +26,6 @@ async def on_button_click(self, inter: discord.MessageInteraction):
2926

3027
Log.info(f"{inter.author.name} tried to close a help thread, but did not have permissions.")
3128

32-
if inter.component.custom_id == "summon_helpers_button":
33-
# Get time
34-
creation_time = inter.channel.create_timestamp
35-
current_time = datetime.datetime.now(creation_time.tzinfo)
36-
time_difference = current_time - creation_time
37-
time_difference_seconds = time_difference.total_seconds()
38-
time_difference_minutes = time_difference_seconds / 60
39-
40-
# Get helper role
41-
role = inter.guild.get_role(variables.helper)
42-
channel = inter.channel.parent.id
43-
if (inter.channel.owner_id == inter.author.id) or (
44-
role in inter.author.roles
45-
):
46-
if time_difference_minutes >= 30 or role in inter.author.roles:
47-
await inter.response.send_message(
48-
f"<@&{variables.helper!s}> <@&{variables.comm_helper_B!s}>",
49-
embed=discord.Embed(
50-
colour=discord.Colour.blue(),
51-
title=("🙇 Helpers Arise!"),
52-
description=(
53-
"Please note that you still might not immediately get a response since all helpers are human beings and volunteers (and also might be sleeping right now)"
54-
),
55-
).set_footer(
56-
text=("Requested by " + inter.user.name),
57-
icon_url=inter.user.avatar,
58-
),
59-
allowed_mentions=discord.AllowedMentions(roles=True),
60-
)
61-
62-
embed = discord.Embed(
63-
colour=discord.Colour.orange(),
64-
title="Someone will come and help soon!",
65-
description="💬 While you wait, take this time to provide more context and details.\n\n✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run `/resolve`"
66-
)
67-
resolve_question_button = discord.ui.Button(
68-
label="Resolve Question",
69-
custom_id="resolve_question_button",
70-
style=discord.ButtonStyle.green,
71-
emoji="✅",
72-
)
73-
74-
await inter.message.edit(
75-
embed=embed, components=[resolve_question_button]
76-
)
77-
78-
Log.info(f"{inter.author.name} summoned helpers")
79-
80-
else:
81-
embed = discord.Embed(
82-
colour=discord.Colour.red(),
83-
title="🕑 Be patient!",
84-
description=(
85-
f"Typically, you should get a response within 10 minutes, but our helpers are volunteers. We therefore need you to wait until <t:{int((datetime.datetime.now() + datetime.timedelta(minutes=30 - time_difference_minutes)).timestamp())}:t> before you use this button.\n\nIf nobody has helped you yet, try rephrasing your question, giving more details, or just being patient."
86-
),
87-
)
88-
await inter.response.send_message(embed=embed, ephemeral=True)
89-
90-
Log.info(f"{inter.author.name} tried to summon helpers, but still has {str(30 - int(time_difference_minutes))} minutes left.")
91-
else:
92-
embed = discord.Embed(
93-
colour=discord.Colour.red(),
94-
title="❌ Summon Helpers",
95-
description="You can't do this since you are neither a helper nor the owner of this channel!",
96-
)
97-
await inter.response.send_message(embed=embed, ephemeral=True)
98-
9929
if inter.component.custom_id == "del_this_button":
10030
await inter.message.delete()
10131
if inter.component.custom_id == "close_report":

modules/fun/commands/suspension.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,31 @@ class SuspensionRailwayCommand(commands.Cog, name="suspension_railway"):
4646
def __init__(self, bot):
4747
self.bot = bot
4848

49-
@commands.slash_command(name="susprail")
50-
async def susprail(self, inter: discord.ApplicationContext):
51-
return
49+
susprail = discord.SlashCommandGroup(name="susprail")
5250

53-
@susprail.sub_command("image","Generate a random image of a suspension railway")
51+
@susprail.command(description="Generate a random image of a suspension railway")
5452
async def image(self, inter: discord.ApplicationContext):
5553
image = random.choice(IMAGES)
5654
embed = discord.Embed(
5755
title=image["title"],
5856
colour=discord.Colour.blue()
59-
).set_image(image["url"]).set_footer(text=image["credits"])
57+
).set_image(url=image["url"]).set_footer(text=image["credits"])
6058
await inter.response.send_message(embed=embed)
6159

62-
@susprail.sub_command("info","Learn about suspension railways")
60+
@susprail.command(description="Learn about suspension railways")
6361
async def info(self, inter: discord.ApplicationContext):
6462
embed = discord.Embed(
6563
title="Learn about Suspension Railways",
6664
colour=discord.Colour.blue()
6765
)
68-
embed.add_field("What are suspension railways?","A suspension railway is a type of elevated monorail. The suspension railway vehicles are suspended from a single, fixed track (not a cable). This makes them good for being built above streets or even other railway types.",inline=False)
69-
embed.add_field("What suspension railways are there?","There are many suspension railways including the following:\n- **Schwebebahn** in Wuppertal, Germany\n- **Schwebebahn** in Dresden, Germany\n- **H-Bahn** in TU Dortmund, Germany\n- **Sky train** in Dusseldorf Airport, Germany\n- **Strela** in Glukhovo , Russia\n- **Shonan** in Kanagawa Prefecture, Japan\n- **Chiba Urban** in Chiba, Japan\n- **SkyTrain** in Chengdu, China\n- **Optics Valley** in Wuhan, China\n- **Red Rail** in Xingguo, China",inline=False)
66+
embed.add_field(
67+
name="What are suspension railways?",
68+
value="A suspension railway is a type of elevated monorail. The suspension railway vehicles are suspended from a single, fixed track (not a cable). This makes them good for being built above streets or even other railway types.",
69+
inline=False
70+
)
71+
embed.add_field(
72+
name="What suspension railways are there?",
73+
value="There are many suspension railways including the following:\n- **Schwebebahn** in Wuppertal, Germany\n- **Schwebebahn** in Dresden, Germany\n- **H-Bahn** in TU Dortmund, Germany\n- **Sky train** in Dusseldorf Airport, Germany\n- **Strela** in Glukhovo , Russia\n- **Shonan** in Kanagawa Prefecture, Japan\n- **Chiba Urban** in Chiba, Japan\n- **SkyTrain** in Chengdu, China\n- **Optics Valley** in Wuhan, China\n- **Red Rail** in Xingguo, China",
74+
inline=False
75+
)
7076
await inter.response.send_message(embed=embed)

modules/fun/commands/uwu.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ class UwuCommand(commands.Cog, name="uwu"):
1010
def __init__(self, bot):
1111
self.bot = bot
1212

13-
@commands.slash_command(name="uwu")
14-
async def uwu(self, inter: discord.ApplicationContext):
15-
return
13+
uwu = discord.SlashCommandGroup(name="uwu")
1614

17-
@uwu.sub_command("message","Send an uwufied message")
15+
@uwu.command(description="Send an uwufied message")
1816
async def message(self, inter: discord.ApplicationContext, text: str):
1917
hooks = await inter.channel.webhooks()
2018

@@ -28,7 +26,7 @@ async def message(self, inter: discord.ApplicationContext, text: str):
2826
await inter.response.send_message("yes done",ephemeral=True)
2927
Log.info(f"Uwufied a message from {inter.author.name} in #{inter.channel.name}")
3028

31-
@uwu.sub_command("auto","Enable the auto uwufier")
29+
@uwu.command(description="Enable the auto uwufier")
3230
async def auto(self, inter: discord.ApplicationContext):
3331
try:
3432
users = uwu_data["users"]
@@ -44,7 +42,7 @@ async def auto(self, inter: discord.ApplicationContext):
4442
except Exception as e:
4543
Log.error(f"Could not toggle uwufier for user {inter.author.name}: {e}")
4644

47-
@uwu.sub_command("channel","Enable the auto uwufier for the current channel")
45+
@uwu.command(description="Enable the auto uwufier for the current channel")
4846
async def channel(self, inter: discord.ApplicationContext):
4947
try:
5048
if inter.channel.id in uwu_data["channels"]:
@@ -58,7 +56,7 @@ async def channel(self, inter: discord.ApplicationContext):
5856
except Exception as e:
5957
Log.error(f"Could not toggle uwufier for channel #{inter.channel.name}: {e}")
6058

61-
@uwu.sub_command("ban","Ban a user from using the uwu features")
59+
@uwu.command(description="Ban a user from using the uwu features")
6260
async def ban(self, inter: discord.ApplicationContext, user: discord.Member):
6361
try:
6462
if user.id in uwu_data["banned"]:
@@ -72,8 +70,8 @@ async def ban(self, inter: discord.ApplicationContext, user: discord.Member):
7270
except Exception as e:
7371
Log.error(f"Could not ban user {user.name} from the uwufier: {e}")
7472

75-
@uwu.sub_command("user","Enable the auto uwufier for another user")
76-
async def auto(self, inter: discord.ApplicationContext, user: discord.Member):
73+
@uwu.command(description="Enable the auto uwufier for another user")
74+
async def user(self, inter: discord.ApplicationContext, user: discord.Member):
7775
try:
7876
users = uwu_data["users"]
7977
if user.id in users:
@@ -88,7 +86,7 @@ async def auto(self, inter: discord.ApplicationContext, user: discord.Member):
8886
except Exception as e:
8987
Log.error(f"Could not toggle uwufier for user {user.name}: {e}")
9088

91-
@uwu.sub_command("override","Toggle all uwu features")
89+
@uwu.command(description="Toggle all uwu features")
9290
async def override(self, inter: discord.ApplicationContext):
9391
try:
9492
if uwu_data["enabled"]:

modules/help_channels/commands/resolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def resolve(self, inter: discord.ApplicationContext):
2121
return False
2222

2323
if (inter.channel.owner_id == inter.author.id) or (role in inter.author.roles) and channel in variables.help_channels:
24-
await resolve_thread(inter.channel, inter.response, inter.author)
24+
await resolve_thread(inter.channel, inter.response)
2525
else:
2626
await inter.response.send_message("You aren't allowed to do this here.", ephemeral=True)
2727
Log.info(f"{inter.author.name} tried to resolve a thread which wasn't theirs")
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import discord
2+
import variables
3+
from utils.res_thread import resolve_thread
4+
5+
class SummonHelpersButton(discord.ui.Button):
6+
def __init__(self, enabled = True):
7+
super().__init__(
8+
label="Summon Helpers",
9+
custom_id="summon_helpers_button",
10+
style=discord.ButtonStyle.blurple,
11+
emoji="🙇",
12+
disabled=enabled
13+
)
14+
15+
async def callback(self, inter: discord.Interaction):
16+
# Get helper role
17+
role = inter.guild.get_role(variables.helper)
18+
19+
# Check user has permission
20+
if not (
21+
inter.channel.owner_id == inter.user.id or
22+
role in inter.user.roles
23+
):
24+
return await inter.respond("Only the original poster and staff members do this!",ephemeral=True)
25+
26+
# Check that it has been half an hour
27+
time_difference = discord.utils.utcnow() - inter.message.channel.created_at
28+
time_difference_minutes = time_difference.total_seconds() / 60
29+
30+
if time_difference_minutes < 2 and (not role in inter.user.roles):
31+
return await inter.respond("**Please be patient!** It has not been long enough to summon helpers. Please wait a bit more before trying again.",ephemeral=True)
32+
33+
# Ping helpers
34+
await inter.response.send_message(
35+
f"<@&{variables.helper!s}> <@&{variables.comm_helper_B!s}>",
36+
embed=discord.Embed(
37+
colour=discord.Colour.blue(),
38+
title=("🙇 Helpers Arise!"),
39+
description="I've pinged the staff members. Our staff are volunteers, so please be respectful, and mindful that we all have lives outside of Discord.",
40+
).set_footer(text="Requested by " + inter.user.name, icon_url=inter.user.avatar),
41+
allowed_mentions=discord.AllowedMentions(roles=True)
42+
)
43+
44+
await inter.respond("Done!",ephemeral=True)
45+
46+
# Edit the thing out
47+
from modules.help_channels.components.views import HelpChannelMessageView
48+
await inter.message.edit(view=HelpChannelMessageView(created_at=inter.message.created_at, summoned=True))
49+
50+
class ResolveQuestionButton(discord.ui.Button):
51+
def __init__(self):
52+
super().__init__(
53+
label="Resolve Question",
54+
custom_id="resolve_question_button",
55+
style=discord.ButtonStyle.green,
56+
emoji="✅"
57+
)
58+
59+
async def callback(self, inter: discord.Interaction):
60+
role = inter.guild.get_role(variables.helper)
61+
if (inter.channel.owner_id == inter.user.id) or (role in inter.user.roles):
62+
await resolve_thread(inter.channel, inter.response)
63+
else:
64+
await inter.respond("Only the original poster and staff members do this!",ephemeral=True)

0 commit comments

Comments
 (0)