mirror of
https://github.com/miaowware/qrm2.git
synced 2025-02-03 09:44:07 -05:00
migrate to pycord
This commit is contained in:
parent
adffd82127
commit
c7ea5e0998
@ -21,7 +21,7 @@ import aiohttp
|
|||||||
|
|
||||||
import discord
|
import discord
|
||||||
import discord.ext.commands as commands
|
import discord.ext.commands as commands
|
||||||
from discord import Emoji, Reaction, PartialEmoji
|
from discord import Emoji, PartialEmoji
|
||||||
|
|
||||||
import data.options as opt
|
import data.options as opt
|
||||||
|
|
||||||
@ -161,7 +161,8 @@ class GlobalChannelConverter(commands.IDConverter):
|
|||||||
def embed_factory(ctx: commands.Context) -> discord.Embed:
|
def embed_factory(ctx: commands.Context) -> discord.Embed:
|
||||||
"""Creates an embed with neutral colour and standard footer."""
|
"""Creates an embed with neutral colour and standard footer."""
|
||||||
embed = discord.Embed(timestamp=datetime.utcnow(), colour=colours.neutral)
|
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
|
return embed
|
||||||
|
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ def error_embed_factory(ctx: commands.Context, exception: Exception, debug_mode:
|
|||||||
return embed
|
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:
|
try:
|
||||||
await msg.add_reaction(react)
|
await msg.add_reaction(react)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
flake8
|
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.title = await self.get_command_signature(group)
|
||||||
embed.description = group.help
|
embed.description = group.help
|
||||||
for cmd in await self.filter_commands(group.commands, sort=True):
|
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)
|
await self.context.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@ -177,7 +178,7 @@ class BaseCog(commands.Cog):
|
|||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
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}"
|
self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}"
|
||||||
f"&scope=bot&permissions={opt.invite_perms}")
|
f"&scope=bot&permissions={opt.invite_perms}")
|
||||||
|
|
||||||
@ -196,7 +197,8 @@ class BaseCog(commands.Cog):
|
|||||||
inline=False)
|
inline=False)
|
||||||
if opt.enable_invite_cmd and (await self.bot.application_info()).bot_public:
|
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.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)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.command(name="ping", aliases=["beep"], category=cmn.BoltCats.INFO)
|
@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.guild_messages = True
|
||||||
intents.dm_messages = True
|
intents.dm_messages = True
|
||||||
intents.reactions = True
|
intents.reactions = True
|
||||||
|
intents.message_content = True
|
||||||
|
|
||||||
member_cache = discord.MemberCacheFlags.from_intents(intents)
|
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)
|
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||||
print(f"[**] Restarting! Requested by {ctx.author}.")
|
print(f"[**] Restarting! Requested by {ctx.author}.")
|
||||||
exit_code = 42 # Signals to the wrapper script that the bot needs to be restarted.
|
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)
|
@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)
|
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
||||||
print(f"[**] Shutting down! Requested by {ctx.author}.")
|
print(f"[**] Shutting down! Requested by {ctx.author}.")
|
||||||
exit_code = 0 # Signals to the wrapper script that the bot should not be restarted.
|
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)
|
@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."""
|
"""Loads an extension."""
|
||||||
try:
|
try:
|
||||||
bot.load_extension(ext_dir + "." + extension)
|
bot.load_extension(ext_dir + "." + extension)
|
||||||
except commands.ExtensionNotFound as e:
|
except discord.errors.ExtensionNotFound as e:
|
||||||
try:
|
try:
|
||||||
bot.load_extension(plugin_dir + "." + extension)
|
bot.load_extension(plugin_dir + "." + extension)
|
||||||
except commands.ExtensionNotFound:
|
except discord.errors.ExtensionNotFound:
|
||||||
raise e
|
raise e
|
||||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
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)
|
await cmn.add_react(ctx.message, pika)
|
||||||
try:
|
try:
|
||||||
bot.reload_extension(ext_dir + "." + extension)
|
bot.reload_extension(ext_dir + "." + extension)
|
||||||
except commands.ExtensionNotLoaded as e:
|
except discord.errors.ExtensionNotLoaded as e:
|
||||||
try:
|
try:
|
||||||
bot.reload_extension(plugin_dir + "." + extension)
|
bot.reload_extension(plugin_dir + "." + extension)
|
||||||
except commands.ExtensionNotLoaded:
|
except discord.errors.ExtensionNotLoaded:
|
||||||
raise e
|
raise e
|
||||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
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."""
|
"""Unloads an extension."""
|
||||||
try:
|
try:
|
||||||
bot.unload_extension(ext_dir + "." + extension)
|
bot.unload_extension(ext_dir + "." + extension)
|
||||||
except commands.ExtensionNotLoaded as e:
|
except discord.errors.ExtensionNotLoaded as e:
|
||||||
try:
|
try:
|
||||||
bot.unload_extension(plugin_dir + "." + extension)
|
bot.unload_extension(plugin_dir + "." + extension)
|
||||||
except commands.ExtensionNotLoaded:
|
except discord.errors.ExtensionNotLoaded:
|
||||||
raise e
|
raise e
|
||||||
await cmn.add_react(ctx.message, cmn.emojis.check_mark)
|
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
|
ctyparser~=2.0
|
||||||
gridtools~=1.0
|
gridtools~=1.0
|
||||||
qrztools[async]~=1.0
|
qrztools[async]~=1.0
|
||||||
|
4
run.sh
4
run.sh
@ -34,9 +34,9 @@ while [ ! -z "$1" ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# If $PYTHON_BIN is not defined, default to 'python3.9'
|
# If $PYTHON_BIN is not defined, default to 'python3.11'
|
||||||
if [ $_NO_BOTENV -eq 1 -a -z "$PYTHON_BIN" ]; then
|
if [ $_NO_BOTENV -eq 1 -a -z "$PYTHON_BIN" ]; then
|
||||||
PYTHON_BIN='python3.9'
|
PYTHON_BIN='python3.11'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user