Skip to content

Commit 6e577c9

Browse files
authored
Merge pull request #24 from Datapack-Hub/pycord
Pycord and major rewrite
2 parents 806a172 + e968bd8 commit 6e577c9

File tree

37 files changed

+1055
-1578
lines changed

37 files changed

+1055
-1578
lines changed

index.py

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import utils.log as Log
2-
import disnake
3-
from disnake.ext import commands, tasks
2+
import discord
3+
from discord.ext import tasks
44
from bottoken import TOKEN
55
import variables
66
import time
7-
from datetime import datetime, timedelta, timezone
8-
import defs
9-
from utils.stats import update
107

118

129

1310
# Setup bot
14-
bot = commands.InteractionBot(
11+
bot = discord.Bot(
1512
test_guilds=[variables.guild],
16-
intents=disnake.Intents.all(),
13+
intents=discord.Intents.all(),
1714
)
1815

1916
# Logs
@@ -25,18 +22,14 @@
2522
bot.add_cog(ModerationListeners(bot))
2623
from modules.moderation.commands.mod import ModCommand
2724
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))
3225

3326
# Help Channels
3427
from modules.help_channels.listeners import HelpChannelListeners
3528
bot.add_cog(HelpChannelListeners(bot))
3629
from modules.help_channels.commands.resolve import ResolveCommand
3730
bot.add_cog(ResolveCommand(bot))
38-
from modules.help_channels.commands.summon import SummonCommand
39-
bot.add_cog(SummonCommand(bot))
31+
from modules.help_channels.commands.question import QuestionCommand
32+
bot.add_cog(QuestionCommand(bot))
4033
from modules.help_channels.commands.top import TopCommand
4134
bot.add_cog(TopCommand(bot))
4235
from modules.help_channels.message_commands.redirect import RedirectCommand
@@ -66,26 +59,16 @@
6659
from modules.welcome.listeners import WelcomeListeners
6760
bot.add_cog(WelcomeListeners(bot))
6861

69-
# Events
70-
from modules.events.button_click import OnButtonClick
71-
bot.add_cog(OnButtonClick(bot))
72-
73-
# Stats
74-
from modules.stats.commands.stats import StatsCommand
75-
bot.add_cog(StatsCommand(bot))
76-
from modules.stats.commands.stats_admin import StatsAdminCommand
77-
bot.add_cog(StatsAdminCommand(bot))
78-
7962
# QOTD
80-
from modules.qotd.schedule import schedule_qotd
63+
# from modules.qotd.schedule import schedule_qotd
8164

8265
# Loops
8366
@tasks.loop(minutes=10)
8467
async def ten():
85-
channel_asked: disnake.VoiceChannel = bot.get_channel(variables.stats_asked)
68+
channel_asked: discord.VoiceChannel = bot.get_channel(variables.stats_asked)
8669
total_threads = 0
8770
for i in variables.help_channels:
88-
channel: disnake.ForumChannel = bot.get_channel(i)
71+
channel: discord.ForumChannel = bot.get_channel(i)
8972
questions = len(channel.threads)
9073
archived_qns = await channel.archived_threads(limit=None).flatten()
9174
for _ in channel.threads:
@@ -99,46 +82,13 @@ async def ten():
9982

10083
await channel_asked.edit(name=f"Questions Asked: {total_threads}")
10184

102-
@tasks.loop(hours=1)
103-
async def autoclose_loop():
104-
for i in variables.help_channels:
105-
forum_channel: disnake.ForumChannel = bot.get_channel(i)
106-
for thread in forum_channel.threads:
107-
last = await thread.history(limit=1).flatten()
108-
last = last[0]
109-
if last:
110-
diff = datetime.now(timezone.utc) - last.created_at
111-
if diff > timedelta(days=3):
112-
try:
113-
resolved_tag = thread.parent.get_tag_by_name("Resolved")
114-
await thread.add_tags(resolved_tag)
115-
except Exception as e:
116-
Log.error("Could not add or find the resolved tag: " + " ".join(e.args))
117-
await thread.send("-# Error resolving this thread.")
118-
else:
119-
await thread.send(
120-
embed=disnake.Embed(
121-
title="Closed for inactivity",
122-
description="This question has been inactive for some time, so it's going to be closed for inactivity. If you still need it, please disregard this message.",
123-
colour=disnake.Colour.dark_gray(),
124-
).set_footer(text="Any further messages or reactions will re-open this thread.")
125-
)
126-
127-
await thread.edit(archived=True)
128-
Log.info(f"Autoclosed thread {thread.name}")
129-
130-
try:
131-
await update(thread)
132-
except Exception as e:
133-
Log.error("Could not log thread to stats data: " + ' '.join(e.args))
134-
85+
from modules.help_channels import loops
13586

13687
@bot.event
13788
async def on_ready():
13889
Log.info("Bot has started!")
13990

140-
await autoclose_loop.start()
141-
await schedule_qotd(bot)
91+
await loops.autoclose_loop.start(bot=bot)
14292

14393
# Run bot
14494
bot.run(TOKEN)

modules/events/button_click.py

Lines changed: 0 additions & 111 deletions
This file was deleted.

modules/fun/commands/suspension.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22

3-
import disnake
4-
from disnake.ext import commands
3+
import discord
4+
55

66
IMAGES = [
77
{
@@ -42,29 +42,35 @@
4242
]
4343

4444

45-
class SuspensionRailwayCommand(commands.Cog, name="suspension_railway"):
45+
class SuspensionRailwayCommand(discord.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: disnake.ApplicationCommandInteraction):
51-
return
49+
susprail = discord.SlashCommandGroup(name="susprail")
5250

53-
@susprail.sub_command("image","Generate a random image of a suspension railway")
54-
async def image(self, inter: disnake.ApplicationCommandInteraction):
51+
@susprail.command(description="Generate a random image of a suspension railway")
52+
async def image(self, inter: discord.ApplicationContext):
5553
image = random.choice(IMAGES)
56-
embed = disnake.Embed(
54+
embed = discord.Embed(
5755
title=image["title"],
58-
colour=disnake.Colour.blue()
59-
).set_image(image["url"]).set_footer(text=image["credits"])
56+
colour=discord.Colour.blue()
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")
63-
async def info(self, inter: disnake.ApplicationCommandInteraction):
64-
embed = disnake.Embed(
60+
@susprail.command(description="Learn about suspension railways")
61+
async def info(self, inter: discord.ApplicationContext):
62+
embed = discord.Embed(
6563
title="Learn about Suspension Railways",
66-
colour=disnake.Colour.blue()
64+
colour=discord.Colour.blue()
65+
)
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
6775
)
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)
7076
await inter.response.send_message(embed=embed)

0 commit comments

Comments
 (0)