Skip to content

Commit 561dffa

Browse files
authored
Merge pull request #155 from onerandomusername/migrate-to-disnake
feat: migrate to disnake and dpy 2.0
2 parents 840e150 + 7ab5b70 commit 561dffa

29 files changed

+574
-423
lines changed

bot/bot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import asyncpg
66
from aiohttp import ClientSession
77
from bot.postgres import create_tables
8-
from discord import AllowedMentions, Embed, Intents, Object
9-
from discord.ext import commands
8+
from disnake import AllowedMentions, Embed, Intents, Object
9+
from disnake.ext import commands
1010
from loguru import logger
1111

1212
from . import constants
@@ -105,7 +105,9 @@ async def startup_greeting(self) -> None:
105105
"""Announce presence to the devlog channel."""
106106
embed = Embed(description="Connected!")
107107
embed.set_author(
108-
name="Gurkbot", url=constants.BOT_REPO_URL, icon_url=self.user.avatar_url
108+
name="Gurkbot",
109+
url=constants.BOT_REPO_URL,
110+
icon_url=self.user.display_avatar.url,
109111
)
110112
await self.get_channel(constants.Channels.devlog).send(embed=embed)
111113

bot/converters.py

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

33

44
class OffTopicName(Converter):

bot/exts/backend/error_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import random
33
from typing import Optional
44

5-
import discord
5+
import disnake
66
from bot.constants import Channels, Colours, ERROR_REPLIES
7-
from discord import Embed, Message
8-
from discord.ext import commands
7+
from disnake import Embed, Message
8+
from disnake.ext import commands
99
from loguru import logger
1010

1111

@@ -140,7 +140,7 @@ async def handle_unexpected_error(
140140
)
141141
try:
142142
dev_alerts = await self.bot.fetch_channel(Channels.devalerts)
143-
except discord.HTTPException as discord_exc:
143+
except disnake.HTTPException as discord_exc:
144144
logger.exception("Fetch failed", exc_info=discord_exc)
145145
return
146146

bot/exts/fun/bonker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from io import BytesIO
55
from typing import Dict
66

7-
import discord
7+
import disnake
88
from PIL import Image, ImageDraw, ImageFile, ImageSequence
9-
from discord.ext import commands
9+
from disnake.ext import commands
1010
from loguru import logger
1111

1212
ImageFile.LOAD_TRUNCATED_IMAGES = True
@@ -97,9 +97,9 @@ def _generate_gif(self, pfp: bytes) -> BytesIO:
9797

9898
@commands.command()
9999
@commands.max_concurrency(3)
100-
async def bonk(self, ctx: commands.Context, member: discord.User) -> None:
100+
async def bonk(self, ctx: commands.Context, member: disnake.User) -> None:
101101
"""Sends gif of mentioned member being "bonked" by Yoda."""
102-
pfp = await member.avatar_url.read()
102+
pfp = await member.display_avatar.read()
103103
created_at = ctx.message.created_at.strftime("%Y-%m-%d_%H-%M")
104104
out_filename = f"bonk_{member.id}_{created_at}.gif"
105105
func = functools.partial(self._generate_gif, pfp)
@@ -109,7 +109,7 @@ async def bonk(self, ctx: commands.Context, member: discord.User) -> None:
109109
out_gif = await asyncio.get_running_loop().run_in_executor(pool, func)
110110

111111
out_gif.seek(0)
112-
await ctx.send(file=discord.File(out_gif, out_filename))
112+
await ctx.send(file=disnake.File(out_gif, out_filename))
113113

114114

115115
def setup(bot: commands.Bot) -> None:

bot/exts/fun/ciphers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from bot.bot import Bot
55
from bot.constants import Colours
6-
from discord import Embed
7-
from discord.ext.commands import BadArgument, Cog, Context, group
6+
from disnake import Embed
7+
from disnake.ext.commands import BadArgument, Cog, Context, group
88

99
logger = logging.getLogger(__name__)
1010

bot/exts/fun/off_topic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from bot.converters import OffTopicName as OT_Converter
99
from bot.postgres.utils import db_execute, db_fetch
1010
from bot.utils.pagination import LinePaginator
11-
from discord import Embed, Reaction, TextChannel, User
12-
from discord.ext.commands import Cog, Context, group, has_any_role
13-
from discord.utils import sleep_until
11+
from disnake import Embed, Reaction, TextChannel, User
12+
from disnake.ext.commands import Cog, Context, group, has_any_role
13+
from disnake.utils import sleep_until
1414
from fuzzywuzzy import fuzz
1515
from loguru import logger
1616

bot/exts/fun/xkcd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from bot.bot import Bot
88
from bot.constants import Colours
9-
from discord import Embed
10-
from discord.ext import tasks
11-
from discord.ext.commands import Cog, Context, command
9+
from disnake import Embed
10+
from disnake.ext import tasks
11+
from disnake.ext.commands import Cog, Context, command
1212

1313
log = logging.getLogger(__name__)
1414

bot/exts/github/_issues.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from random import choice
22
from typing import Optional
33

4-
import discord
4+
import disnake
55
from aiohttp import ClientSession
66
from bot.constants import Channels, ERROR_REPLIES, Emojis
7-
from discord import Embed
8-
from discord.ext import commands
7+
from disnake import Embed
8+
from disnake.ext import commands
99
from loguru import logger
1010

1111
BAD_RESPONSE = {
@@ -28,23 +28,23 @@ def __init__(self, http_session: ClientSession) -> None:
2828
self.http_session = http_session
2929

3030
@staticmethod
31-
def get_repo(channel: discord.TextChannel) -> Optional[str]:
31+
def get_repo(channel: disnake.TextChannel) -> Optional[str]:
3232
"""Get repository for the particular channel."""
3333
return REPO_CHANNEL_MAP.get(channel.id, "gurkbot")
3434

3535
@staticmethod
3636
def error_embed(error_msg: str) -> Embed:
3737
"""Generate Error Embed for Issues command."""
38-
embed = discord.Embed(
38+
embed = disnake.Embed(
3939
title=choice(ERROR_REPLIES),
40-
color=discord.Color.red(),
40+
color=disnake.Color.red(),
4141
description=error_msg,
4242
)
4343
return embed
4444

4545
async def issue(
4646
self,
47-
channel: discord.TextChannel,
47+
channel: disnake.TextChannel,
4848
numbers: commands.Greedy[int],
4949
repository: Optional[str],
5050
user: str,
@@ -104,8 +104,8 @@ async def issue(
104104
)
105105
)
106106

107-
resp = discord.Embed(
108-
colour=discord.Color.green(),
107+
resp = disnake.Embed(
108+
colour=disnake.Color.green(),
109109
description="\n".join("{0} [{1}]({2})".format(*link) for link in links),
110110
)
111111
resp.set_author(name="GitHub", url=f"https://github.com/{user}/{repository}")

bot/exts/github/_profile.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from random import choice
33
from typing import Optional
44

5-
import discord
5+
import disnake
66
from aiohttp import ClientSession
77
from bot.constants import ERROR_REPLIES
8-
from discord import Embed
8+
from disnake import Embed
99

1010

1111
class GithubInfo:
@@ -33,12 +33,12 @@ def get_data(username: Optional[str], user_data: dict, org_data: dict) -> Embed:
3333
else:
3434
blog = "-"
3535

36-
embed = discord.Embed(
36+
embed = disnake.Embed(
3737
title=f"{user_data['login']}'s GitHub profile info",
3838
description=f"```{user_data['bio']}```\n"
3939
if user_data["bio"] is not None
4040
else "",
41-
colour=discord.Colour.green(),
41+
colour=disnake.Colour.green(),
4242
url=user_data["html_url"],
4343
timestamp=datetime.strptime(
4444
user_data["created_at"], "%Y-%m-%dT%H:%M:%SZ"
@@ -76,11 +76,11 @@ async def get_github_info(self, username: str) -> Embed:
7676

7777
# User_data will not have a message key if the user exists
7878
if user_data.get("message") is not None:
79-
embed = discord.Embed(
79+
embed = disnake.Embed(
8080
title=choice(ERROR_REPLIES),
8181
description=f"The profile for `{username}` was not found.",
8282
url=Embed.Empty,
83-
colour=discord.Colour.red(),
83+
colour=disnake.Colour.red(),
8484
)
8585
return embed
8686

bot/exts/github/_source.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from textwrap import dedent
44
from typing import Optional
55

6-
import discord
6+
import disnake
77
from aiohttp import ClientSession
88
from bot import constants
9-
from discord.ext.commands import Command
9+
from disnake.ext.commands import Command
1010

1111
doc_reg_class = r'("""|\'\'\')([\s\S]*?)(\1\s*)'
1212

@@ -15,13 +15,13 @@ class Source:
1515
"""Displays information about the bot's source code."""
1616

1717
def __init__(
18-
self, http_session: ClientSession, bot_avatar: discord.asset.Asset
18+
self, http_session: ClientSession, bot_avatar: disnake.asset.Asset
1919
) -> None:
2020
self.http_session = http_session
2121
self.MAX_FIELD_LENGTH = 500
2222
self.bot_avatar = bot_avatar
2323

24-
async def inspect(self, cmd: Optional[Command]) -> Optional[discord.Embed]:
24+
async def inspect(self, cmd: Optional[Command]) -> Optional[disnake.Embed]:
2525
"""Display information and a GitHub link to the source code of a command."""
2626
if cmd is None:
2727
return
@@ -48,7 +48,7 @@ async def inspect(self, cmd: Optional[Command]) -> Optional[discord.Embed]:
4848
+ "\n... (truncated - too many lines)"
4949
)
5050

51-
embed = discord.Embed(title="Gurkbot's Source Link", description=f"{url}")
51+
embed = disnake.Embed(title="Gurkbot's Source Link", description=f"{url}")
5252
embed.add_field(
5353
name="Source Code Snippet", value=f"```python\n{sanitized}\n```"
5454
)

0 commit comments

Comments
 (0)