Skip to content

Commit 3ba66fb

Browse files
committed
move to disnake, add basic forum support and adapt to various minor changes
1 parent d166ffd commit 3ba66fb

55 files changed

Lines changed: 309 additions & 305 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GearBot/Bot/GearBot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from asyncio import Queue
44
from collections import deque
55

6-
from discord.ext.commands import AutoShardedBot
6+
from disnake.ext.commands import AutoShardedBot
77
from prometheus_client import CollectorRegistry
88

99
from Bot import TheRealGearBot

GearBot/Bot/TheRealGearBot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
import aiohttp
1414
import aioredis
15-
import discord
15+
import disnake
1616
import sentry_sdk
1717
from aiohttp import ClientOSError, ServerDisconnectedError
18-
from discord import Activity, Embed, Colour, Message, TextChannel, Forbidden, ConnectionClosed, Guild, NotFound
19-
from discord.abc import PrivateChannel
20-
from discord.ext import commands
21-
from discord.ext.commands import UnexpectedQuoteError, ExtensionAlreadyLoaded, InvalidEndOfQuotedStringError
18+
from disnake import Activity, Embed, Colour, Message, TextChannel, Forbidden, ConnectionClosed, Guild, NotFound
19+
from disnake.abc import PrivateChannel
20+
from disnake.ext import commands
21+
from disnake.ext.commands import UnexpectedQuoteError, ExtensionAlreadyLoaded, InvalidEndOfQuotedStringError
2222

2323
from Util import Configuration, GearbotLogging, Emoji, Pages, Utils, Translator, InfractionUtils, MessageUtils, \
2424
server_info, DashConfig

GearBot/Cogs/Admin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import datetime
77
from time import time
88

9-
import discord
10-
from discord.ext import commands, tasks
11-
from discord.utils import time_snowflake
9+
import disnake
10+
from disnake.ext import commands, tasks
11+
from disnake.utils import time_snowflake
1212

1313
from Bot.TheRealGearBot import fill_cache
1414
from Cogs.BaseCog import BaseCog
@@ -54,7 +54,7 @@ async def upgrade(self, ctx):
5454
@commands.command()
5555
async def setstatus(self, ctx, type:int, *, status:str):
5656
"""Sets a playing/streaming/listening/watching status"""
57-
await self.bot.change_presence(activity=discord.Activity(name=status, type=type))
57+
await self.bot.change_presence(activity=disnake.Activity(name=status, type=type))
5858
await ctx.send("Status updated")
5959

6060
@commands.command()
@@ -129,7 +129,7 @@ async def post_info(self, ctx, name):
129129
with open(f"{name}.txt", "r") as file:
130130
pages = Pages.paginate("".join(file.readlines()), 500, 2000)
131131
await ctx.channel.purge(limit=len(pages) + 2)
132-
await ctx.send(file=discord.File(f"{name}.png"))
132+
await ctx.send(file=disnake.File(f"{name}.png"))
133133
for page in pages:
134134
await ctx.send(page)
135135

@@ -196,7 +196,7 @@ async def thread_migration(self, ctx):
196196
current.update(use_threads=False, use_private_threads=False)
197197
if not current.is_empty():
198198
await category.set_permissions(role, reason='thread release migration',overwrite=current)
199-
except discord.Forbidden:
199+
except disnake.Forbidden:
200200
await asyncio.sleep(0.1)
201201

202202
# sleep a bit so we have time to receive the update events
@@ -210,7 +210,7 @@ async def thread_migration(self, ctx):
210210
current.update(use_threads=False, use_private_threads=False)
211211
if not current.is_empty():
212212
await channel.set_permissions(role, reason='thread release migration',overwrite=current)
213-
except discord.Forbidden:
213+
except disnake.Forbidden:
214214
pass
215215
await MessageUtils.send_to(ctx, 'YES', 'Thread migration completed!', translate=False)
216216

GearBot/Cogs/AntiRaid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import time
33
import datetime
44

5-
import discord
6-
from discord.ext import commands
5+
import disnake
6+
from disnake.ext import commands
77

88
from Cogs.BaseCog import BaseCog
99
from Util import Configuration, GearbotLogging, MessageUtils
@@ -23,7 +23,7 @@ def __init__(self, bot):
2323
}
2424

2525
@commands.Cog.listener()
26-
async def on_member_join(self, member: discord.Member):
26+
async def on_member_join(self, member: disnake.Member):
2727
raid_settings = Configuration.get_var(member.guild.id, "RAID_HANDLING")
2828
if not raid_settings["ENABLED"]:
2929
return

GearBot/Cogs/AntiSpam.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from asyncio import CancelledError
55
import hashlib
66

7-
import discord
7+
import disnake
88
import emoji
99

1010
import time
1111
from collections import deque
1212

13-
from discord import Object, Forbidden, NotFound, RawMessageDeleteEvent
14-
from discord.channel import TextChannel
15-
from discord.ext import commands
16-
from discord.guild import Guild
17-
from discord.member import Member
18-
from discord.message import Message
19-
from discord.utils import snowflake_time
13+
from disnake import Object, Forbidden, NotFound, RawMessageDeleteEvent
14+
from disnake.channel import TextChannel
15+
from disnake.ext import commands
16+
from disnake.guild import Guild
17+
from disnake.member import Member
18+
from disnake.message import Message
19+
from disnake.utils import snowflake_time
2020

2121
from Bot import TheRealGearBot
2222
from Cogs.BaseCog import BaseCog
@@ -455,7 +455,7 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent):
455455

456456

457457

458-
async def handle_failed_ping(self, message: discord.Message, amount):
458+
async def handle_failed_ping(self, message: disnake.Message, amount):
459459
if self.is_exempt(message.guild.id, message.author) or message.author.bot or message.webhook_id is not None:
460460
return # don't action except users
461461
buckets = Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", [])

GearBot/Cogs/BCVersionChecker.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from concurrent.futures import CancelledError
77

88
import aiohttp
9-
import discord
10-
from discord import Embed, File
11-
from discord.ext import commands
9+
import disnake
10+
from disnake import Embed, File
11+
from disnake.ext import commands
1212

1313
from Cogs.BaseCog import BaseCog
1414
from Util import GearbotLogging, VersionInfo, Permissioncheckers, Configuration, Utils, Emoji, Pages
@@ -52,7 +52,7 @@ async def latest(self, ctx:commands.Context, version=None):
5252
latestBCCinfo = await self.getVersionDetails("BuildCraftCompat", latestBCC)
5353
info = f"{info}\n\nBuildcraft Compat {latestBCC}:\n[Changelog](https://www.mod-buildcraft.com/pages/buildinfo/BuildCraftCompat/changelog/{latestBCC}.html) | [Blog]({latestBCCinfo['blog_entry'] if 'blog_entry' in latestBCCinfo else 'https://www.mod-buildcraft.com'}) | [Direct download]({latestBCCinfo['downloads']['main']})"
5454

55-
embed = discord.Embed(colour=discord.Colour(0x54d5ff), timestamp=datetime.datetime.utcfromtimestamp(time.time()),
55+
embed = disnake.Embed(colour=disnake.Colour(0x54d5ff), timestamp=datetime.datetime.utcfromtimestamp(time.time()),
5656
description=info)
5757
embed.set_author(name=f"BuildCraft releases for {version}", url="https://www.mod-buildcraft.com/pages/download.html", icon_url="https://i.imgur.com/YKGkDDZ.png")
5858
await ctx.send(embed=embed)
@@ -81,21 +81,21 @@ async def cleancache(self, ctx):
8181
# @Permissioncheckers.devOnly()
8282
# async def request_testing(self, ctx:commands.Context, roleName):
8383
# """Make a role pingable for announcements"""
84-
# role = discord.utils.find(lambda r: r.name == roleName, ctx.guild.roles)
84+
# role = disnake.utils.find(lambda r: r.name == roleName, ctx.guild.roles)
8585
# if role is None:
8686
# await ctx.send("Unable to find that role")
8787
# else:
8888
# await role.edit(mentionable=True)
8989
# await ctx.send("Role is now mentionable and awaiting your announcement")
9090
#
91-
# def check(message:discord.Message):
91+
# def check(message:disnake.Message):
9292
# return role in message.role_mentions
9393
# until = datetime.datetime.now() + datetime.timedelta(minutes=1)
9494
#
9595
# done = False
9696
# while not done:
9797
# try:
98-
# message:discord.Message = await self.bot.wait_for('message', check=check, timeout=(until - datetime.datetime.now()).seconds)
98+
# message:disnake.Message = await self.bot.wait_for('message', check=check, timeout=(until - datetime.datetime.now()).seconds)
9999
# if message.author == ctx.author:
100100
# await message.pin()
101101
# done = True
@@ -129,7 +129,7 @@ async def updater(cog:BCVersionChecker):
129129
highestMC = VersionInfo.getLatest(cog.BC_VERSION_LIST.keys())
130130
latestBC = VersionInfo.getLatest(cog.BC_VERSION_LIST[highestMC])
131131
generalID = 309218657798455298
132-
channel:discord.TextChannel = cog.bot.get_channel(generalID)
132+
channel:disnake.TextChannel = cog.bot.get_channel(generalID)
133133
old_latest = Configuration.get_persistent_var("latest_bc", "0.0.0")
134134
Configuration.set_persistent_var("latest_bc", latestBC) # save already so we don't get stuck and keep trying over and over if something goes wrong
135135
if channel is not None and latestBC != old_latest:
@@ -195,7 +195,7 @@ async def updater(cog:BCVersionChecker):
195195
cog.bot.errors = cog.bot.errors + 1
196196
GearbotLogging.error("Something went wrong in the BC version checker task")
197197
GearbotLogging.error(traceback.format_exc())
198-
embed = discord.Embed(colour=discord.Colour(0xff0000),
198+
embed = disnake.Embed(colour=disnake.Colour(0xff0000),
199199
timestamp=datetime.datetime.utcfromtimestamp(time.time()))
200200
embed.set_author(name="Something went wrong in the BC version checker task:")
201201
embed.add_field(name="Exception", value=str(ex))

GearBot/Cogs/BaseCog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from discord.ext import commands
1+
from disnake.ext import commands
22

33
from Bot.GearBot import GearBot
44
from Util import Permissioncheckers

GearBot/Cogs/Basic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import time
44
import datetime
55

6-
import discord
7-
from discord import Embed
8-
from discord.ext import commands
9-
from discord.ext.commands import clean_content, BadArgument
6+
import disnake
7+
from disnake import Embed
8+
from disnake.ext import commands
9+
from disnake.ext.commands import clean_content, BadArgument
1010

1111
from Cogs.BaseCog import BaseCog
1212
from Util import Configuration, Pages, HelpGenerator, Emoji, Translator, Utils, GearbotLogging, \
@@ -45,7 +45,7 @@ async def about(self, ctx):
4545
self_messages = str(self.bot.self_messages)
4646
total = str(sum(len(guild.members) for guild in self.bot.guilds))
4747
unique = str(len(self.bot.users))
48-
embed = discord.Embed(colour=discord.Colour(0x00cea2),
48+
embed = disnake.Embed(colour=disnake.Colour(0x00cea2),
4949
timestamp=datetime.datetime.utcfromtimestamp(time.time()).replace(
5050
tzinfo=datetime.timezone.utc),
5151
description=f"Stats for cluster {self.bot.cluster}\n" +
@@ -74,7 +74,7 @@ async def about(self, ctx):
7474

7575
click_here = Translator.translate('click_here', ctx)
7676
embed.add_field(name=Translator.translate('support_server', ctx),
77-
value=f"[{click_here}](https://discord.gg/vddW3D9)")
77+
value=f"[{click_here}](https://disnake.gg/vddW3D9)")
7878
embed.add_field(name=Translator.translate('website', ctx), value=f"[{click_here}](https://gearbot.rocks)")
7979
embed.add_field(name=f"Github", value=f"[{click_here}](https://github.com/gearbot/GearBot)")
8080
embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.avatar.url)
@@ -110,7 +110,7 @@ async def quote(self, ctx: commands.Context, *, message: Message):
110110
attachments = await LoggedAttachment.filter(message_id=message.id)
111111
if len(attachments) == 1:
112112
attachment = attachments[0]
113-
embed = discord.Embed(colour=discord.Color(0xd5fff),
113+
embed = disnake.Embed(colour=disnake.Color(0xd5fff),
114114
timestamp=message.created_at)
115115
if message.content is None or message.content == "":
116116
if attachment is not None:
@@ -122,7 +122,7 @@ async def quote(self, ctx: commands.Context, *, message: Message):
122122
value=url)
123123
else:
124124
description = message.content
125-
embed = discord.Embed(colour=discord.Color(0xd5fff), description=description,
125+
embed = disnake.Embed(colour=disnake.Color(0xd5fff), description=description,
126126
timestamp=message.created_at)
127127
embed.add_field(name="​",
128128
value=f"[Jump to message]({message.jump_url})")
@@ -185,7 +185,7 @@ async def self_role(self, ctx: commands.Context, *, role: str = None):
185185
await ctx.author.add_roles(role)
186186
await ctx.send(
187187
Translator.translate("role_joined", ctx, role_name=role.name, user=ctx.author))
188-
except discord.Forbidden:
188+
except disnake.Forbidden:
189189
await ctx.send(
190190
f"{Emoji.get_chat_emoji('NO')} {Translator.translate('role_too_high_add', ctx, role=role.name)}")
191191
else:
@@ -213,7 +213,7 @@ async def uid(self, ctx, *, text: str):
213213
await MessageUtils.send_to(ctx, "NO", "no_uids_found")
214214

215215
@commands.Cog.listener()
216-
async def on_guild_role_delete(self, role: discord.Role):
216+
async def on_guild_role_delete(self, role: disnake.Role):
217217
roles = Configuration.get_var(role.guild.id, "ROLES", "SELF_ROLES")
218218
if role.id in roles:
219219
roles.remove(role.id)

GearBot/Cogs/Censor.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from urllib import parse
44
from urllib.parse import urlparse
55

6-
import discord
6+
import disnake
77
import emoji
8-
from discord import DMChannel
9-
from discord.ext import commands
8+
from disnake import DMChannel
9+
from disnake.ext import commands
1010

1111
from Cogs.BaseCog import BaseCog
1212
from Util import Configuration, GearbotLogging, Permissioncheckers, Utils, MessageUtils, Translator
@@ -23,7 +23,7 @@ def __init__(self, bot):
2323
self.regexes = dict()
2424

2525
@commands.Cog.listener()
26-
async def on_message(self, message: discord.Message):
26+
async def on_message(self, message: disnake.Message):
2727
if message.guild is None or message.webhook_id is not None or message.channel is None or isinstance(message.channel, DMChannel) or not Configuration.get_var(message.channel.guild.id, "CENSORING", "ENABLED") or self.bot.user.id == message.author.id:
2828
return
2929
member = await Utils.get_member(self.bot, message.guild, message.author.id, fetch_if_missing=True)
@@ -36,7 +36,7 @@ async def on_message(self, message: discord.Message):
3636
await self.check_message(member, message.content, message.channel, message.id, False, reply, message.attachments)
3737

3838
@commands.Cog.listener()
39-
async def on_raw_message_edit(self, event: discord.RawMessageUpdateEvent):
39+
async def on_raw_message_edit(self, event: disnake.RawMessageUpdateEvent):
4040
channel = self.bot.get_channel(int(event.data["channel_id"]))
4141
m = await MessageUtils.get_message_data(self.bot, event.message_id)
4242
reply = None
@@ -51,7 +51,7 @@ async def on_raw_message_edit(self, event: discord.RawMessageUpdateEvent):
5151
if (permissions.read_messages and permissions.read_message_history) or permissions.administrator:
5252
try:
5353
message = await channel.fetch_message(event.message_id)
54-
except (discord.NotFound, discord.Forbidden): # we should never get forbidden, be we do, somehow
54+
except (disnake.NotFound, disnake.Forbidden): # we should never get forbidden, be we do, somehow
5555
return
5656
else:
5757
author_id = message.author.id
@@ -85,8 +85,8 @@ async def check_message(self, member, content, channel, message_id, edit, reply,
8585
codes = INVITE_MATCHER.findall(decoded_content)
8686
for code in codes:
8787
try:
88-
invite: discord.Invite = await self.bot.fetch_invite(code)
89-
except discord.NotFound:
88+
invite: disnake.Invite = await self.bot.fetch_invite(code)
89+
except disnake.NotFound:
9090
await self.censor_invite(member, message_id, channel, code, "INVALID INVITE", content, edit, reply, attachments)
9191
return
9292
if invite.guild is None:
@@ -163,8 +163,8 @@ async def censor_message(self, message_id, content, channel, member, bad, key=""
163163
if p.manage_messages or p.administrator:
164164
try:
165165
self.bot.deleted_messages.append(message_id)
166-
await channel.delete_messages([discord.Object(message_id)])
167-
except discord.NotFound as ex:
166+
await channel.delete_messages([disnake.Object(message_id)])
167+
except disnake.NotFound as ex:
168168
pass
169169
else:
170170
GearbotLogging.log_key(channel.guild.id, f'censored_message{key}{e}', user=member, user_id=member.id,
@@ -173,7 +173,7 @@ async def censor_message(self, message_id, content, channel, member, bad, key=""
173173
else:
174174
GearbotLogging.log_key(channel.guild.id, f'censored_message_failed{key}{e}', user=member,
175175
user_id=member.id, message=clean_message, sequence=bad,
176-
link='https://discord.com/channels/{0}/{1}/{2}'.format(channel.guild.id, channel.id, message_id),
176+
link='https://disnake.com/channels/{0}/{1}/{2}'.format(channel.guild.id, channel.id, message_id),
177177
reply=reply_str, attachments=attachments_str)
178178
self.bot.dispatch("user_censored", messageholder(message_id, member, channel, channel.guild))
179179

@@ -202,7 +202,7 @@ async def censor_invite(self, member, message_id, channel, code, server_name, co
202202
clean_message = Utils.trim_message(clean_message, 1600 - len(attachments_str) - len(reply_str))
203203
try:
204204
if channel.permissions_for(channel.guild.me).manage_messages:
205-
await channel.delete_messages([discord.Object(message_id)])
205+
await channel.delete_messages([disnake.Object(message_id)])
206206
GearbotLogging.log_key(member.guild.id, f'censored_invite{e}', user=clean_name, code=code, message=clean_message,
207207
server_name=server_name, user_id=member.id,
208208
channel=channel.mention, attachments=attachments_str,
@@ -214,7 +214,7 @@ async def censor_invite(self, member, message_id, channel, code, server_name, co
214214
reply=reply_str)
215215
if message_id in self.bot.deleted_messages:
216216
self.bot.deleted_messages.remove(message_id)
217-
except discord.NotFound:
217+
except disnake.NotFound:
218218
# we failed? guess we lost the race, log anyways
219219
GearbotLogging.log_key(member.guild.id, f'invite_censor_fail{e}', user=clean_name, code=code,
220220
message=clean_message, server_name=server_name, user_id=member.id,

0 commit comments

Comments
 (0)