mirror of
https://github.com/miaowware/qrm2.git
synced 2024-11-25 09:18:52 -05:00
migrate to pycord
This commit is contained in:
parent
adffd82127
commit
c7ea5e0998
@ -21,7 +21,7 @@ import aiohttp
|
||||
|
||||
import discord
|
||||
import discord.ext.commands as commands
|
||||
from discord import Emoji, Reaction, PartialEmoji
|
||||
from discord import Emoji, PartialEmoji
|
||||
|
||||
import data.options as opt
|
||||
|
||||
@ -161,7 +161,8 @@ class GlobalChannelConverter(commands.IDConverter):
|
||||
def embed_factory(ctx: commands.Context) -> discord.Embed:
|
||||
"""Creates an embed with neutral colour and standard footer."""
|
||||
embed = discord.Embed(timestamp=datetime.utcnow(), colour=colours.neutral)
|
||||
embed.set_footer(text=str(ctx.author), icon_url=str(ctx.author.avatar_url))
|
||||
if ctx.author:
|
||||
embed.set_footer(text=str(ctx.author), icon_url=str(ctx.author.avatar.url))
|
||||
return embed
|
||||
|
||||
|
||||
@ -178,7 +179,7 @@ def error_embed_factory(ctx: commands.Context, exception: Exception, debug_mode:
|
||||
return embed
|
||||
|
||||
|
||||
async def add_react(msg: discord.Message, react: Union[Emoji, Reaction, PartialEmoji, str]):
|
||||
async def add_react(msg: discord.Message, react: Union[Emoji, PartialEmoji, str]):
|
||||
try:
|
||||
await msg.add_reaction(react)
|
||||
except discord.Forbidden:
|
||||
|
@ -1,3 +1,3 @@
|
||||
-r requirements.txt
|
||||
flake8
|
||||
discord.py-stubs==1.7.3
|
||||
mypy
|
||||
|
@ -141,7 +141,8 @@ class QrmHelpCommand(commands.HelpCommand):
|
||||
embed.title = await self.get_command_signature(group)
|
||||
embed.description = group.help
|
||||
for cmd in await self.filter_commands(group.commands, sort=True):
|
||||
embed.add_field(name=await self.get_command_signature(cmd), value=cmd.help, inline=False)
|
||||
embed.add_field(name=await self.get_command_signature(cmd), value=cmd.help if cmd.help else "",
|
||||
inline=False)
|
||||
await self.context.send(embed=embed)
|
||||
|
||||
|
||||
@ -177,7 +178,7 @@ class BaseCog(commands.Cog):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
if not self.bot_invite:
|
||||
if not self.bot_invite and self.bot.user:
|
||||
self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}"
|
||||
f"&scope=bot&permissions={opt.invite_perms}")
|
||||
|
||||
@ -196,7 +197,8 @@ class BaseCog(commands.Cog):
|
||||
inline=False)
|
||||
if opt.enable_invite_cmd and (await self.bot.application_info()).bot_public:
|
||||
embed.add_field(name="Invite qrm to Your Server", value=self.bot_invite, inline=False)
|
||||
embed.set_thumbnail(url=str(self.bot.user.avatar_url))
|
||||
if self.bot.user and self.bot.user.avatar:
|
||||
embed.set_thumbnail(url=str(self.bot.user.avatar.url))
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name="ping", aliases=["beep"], category=cmn.BoltCats.INFO)
|
||||
|
17
main.py
17
main.py
@ -52,6 +52,7 @@ intents.guilds = True
|
||||
intents.guild_messages = True
|
||||
intents.dm_messages = True
|
||||
intents.reactions = True
|
||||
intents.message_content = True
|
||||
|
||||
member_cache = discord.MemberCacheFlags.from_intents(intents)
|
||||
|
||||
@ -81,7 +82,7 @@ async def _restart_bot(ctx: commands.Context):
|
||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||
print(f"[**] Restarting! Requested by {ctx.author}.")
|
||||
exit_code = 42 # Signals to the wrapper script that the bot needs to be restarted.
|
||||
await bot.logout()
|
||||
await bot.close()
|
||||
|
||||
|
||||
@bot.command(name="shutdown", aliases=["shut"], category=cmn.BoltCats.ADMIN)
|
||||
@ -92,7 +93,7 @@ async def _shutdown_bot(ctx: commands.Context):
|
||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||
print(f"[**] Shutting down! Requested by {ctx.author}.")
|
||||
exit_code = 0 # Signals to the wrapper script that the bot should not be restarted.
|
||||
await bot.logout()
|
||||
await bot.close()
|
||||
|
||||
|
||||
@bot.group(name="extctl", aliases=["ex"], case_insensitive=True, category=cmn.BoltCats.ADMIN)
|
||||
@ -123,10 +124,10 @@ async def _extctl_load(ctx: commands.Context, extension: str):
|
||||
"""Loads an extension."""
|
||||
try:
|
||||
bot.load_extension(ext_dir + "." + extension)
|
||||
except commands.ExtensionNotFound as e:
|
||||
except discord.errors.ExtensionNotFound as e:
|
||||
try:
|
||||
bot.load_extension(plugin_dir + "." + extension)
|
||||
except commands.ExtensionNotFound:
|
||||
except discord.errors.ExtensionNotFound:
|
||||
raise e
|
||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||
|
||||
@ -140,10 +141,10 @@ async def _extctl_reload(ctx: commands.Context, extension: str):
|
||||
await cmn.add_react(ctx.message, pika)
|
||||
try:
|
||||
bot.reload_extension(ext_dir + "." + extension)
|
||||
except commands.ExtensionNotLoaded as e:
|
||||
except discord.errors.ExtensionNotLoaded as e:
|
||||
try:
|
||||
bot.reload_extension(plugin_dir + "." + extension)
|
||||
except commands.ExtensionNotLoaded:
|
||||
except discord.errors.ExtensionNotLoaded:
|
||||
raise e
|
||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||
|
||||
@ -153,10 +154,10 @@ async def _extctl_unload(ctx: commands.Context, extension: str):
|
||||
"""Unloads an extension."""
|
||||
try:
|
||||
bot.unload_extension(ext_dir + "." + extension)
|
||||
except commands.ExtensionNotLoaded as e:
|
||||
except discord.errors.ExtensionNotLoaded as e:
|
||||
try:
|
||||
bot.unload_extension(plugin_dir + "." + extension)
|
||||
except commands.ExtensionNotLoaded:
|
||||
except discord.errors.ExtensionNotLoaded:
|
||||
raise e
|
||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
discord.py~=1.7.3
|
||||
py-cord~=2.3.2
|
||||
aiohttp[speedups]
|
||||
ctyparser~=2.0
|
||||
gridtools~=1.0
|
||||
qrztools[async]~=1.0
|
||||
|
Loading…
Reference in New Issue
Block a user