Compare commits
No commits in common. "6b9172ef1b656dff17c5da3554faf1e5d64d1f7a" and "47955cdfd5981e86c98d7ee6432e660cd0e2c972" have entirely different histories.
6b9172ef1b
...
47955cdfd5
@ -3,16 +3,13 @@ import inspect
|
|||||||
|
|
||||||
from state import reloaded_modules
|
from state import reloaded_modules
|
||||||
|
|
||||||
from . import bot, tools, utils, voice
|
from . import tools, utils, voice
|
||||||
from .utils import *
|
from .utils import *
|
||||||
|
|
||||||
|
|
||||||
def __reload_module__():
|
def __reload_module__():
|
||||||
for name, module in globals().items():
|
for name, module in globals().items():
|
||||||
if (
|
if inspect.ismodule(module):
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||||
reloaded_modules.add(name)
|
reloaded_modules.add(name)
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
import importlib
|
|
||||||
import inspect
|
|
||||||
import time
|
|
||||||
|
|
||||||
import arguments
|
|
||||||
import constants
|
|
||||||
from state import reloaded_modules, start_time
|
|
||||||
|
|
||||||
import commands
|
|
||||||
import utils
|
|
||||||
|
|
||||||
|
|
||||||
async def uptime(message):
|
|
||||||
tokens = commands.tokenize(message.content)
|
|
||||||
parser = arguments.ArgumentParser(
|
|
||||||
tokens[0],
|
|
||||||
"print bot uptime",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-s",
|
|
||||||
"--since",
|
|
||||||
action="store_true",
|
|
||||||
help="bot up since",
|
|
||||||
)
|
|
||||||
if not (args := await parser.parse_args(message, tokens)):
|
|
||||||
return
|
|
||||||
|
|
||||||
if args.since:
|
|
||||||
await utils.reply(message, f"{round(start_time)}")
|
|
||||||
else:
|
|
||||||
await utils.reply(message, f"up {round(time.time() - start_time)} seconds")
|
|
||||||
|
|
||||||
|
|
||||||
def __reload_module__():
|
|
||||||
for name, module in globals().items():
|
|
||||||
if (
|
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
|
||||||
reloaded_modules.add(name)
|
|
||||||
module.__reload_module__()
|
|
@ -1,77 +1,23 @@
|
|||||||
import importlib
|
|
||||||
import inspect
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import arguments
|
|
||||||
import commands
|
import commands
|
||||||
import constants
|
|
||||||
from state import reloaded_modules
|
|
||||||
|
|
||||||
|
|
||||||
async def clear(message):
|
async def clear(message):
|
||||||
tokens = commands.tokenize(message.content)
|
tokens = commands.tokenize(message.content)[1:]
|
||||||
parser = arguments.ArgumentParser(
|
if len(tokens) < 2:
|
||||||
tokens[0],
|
await message.reply("no count and/or regex supplied!", mention_author=False)
|
||||||
"bulk delete messages in the current channel matching certain criteria",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"count",
|
|
||||||
type=int,
|
|
||||||
choices=range(1, 1001),
|
|
||||||
metavar="[1-1000]",
|
|
||||||
help="amount of messages to delete",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-r",
|
|
||||||
"--regex",
|
|
||||||
required=False,
|
|
||||||
help="delete messages with content matching this regex",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-i",
|
|
||||||
"--author-id",
|
|
||||||
type=int,
|
|
||||||
action="append",
|
|
||||||
help="delete messages whose author matches this id",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-o",
|
|
||||||
"--oldest-first",
|
|
||||||
action="store_true",
|
|
||||||
help="delete oldest messages first",
|
|
||||||
)
|
|
||||||
if not (args := await parser.parse_args(message, tokens)):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def check(m):
|
|
||||||
c = []
|
|
||||||
if r := args.regex:
|
|
||||||
c.append(re.match(r, m.content))
|
|
||||||
if i := args.author_id:
|
|
||||||
c.append(m.author.id in i)
|
|
||||||
return all(c)
|
|
||||||
|
|
||||||
message_count = len(
|
message_count = len(
|
||||||
await message.channel.purge(
|
await message.channel.purge(
|
||||||
limit=args.count, check=check, oldest_first=args.oldest_first
|
limit=int(tokens[0]), check=lambda m: re.match(tokens[1], m.content)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await message.reply(
|
await message.reply(
|
||||||
f"purged **{message_count} {'message' if message_count == 1 else 'messages'}**",
|
f"successfully purged **{message_count} {'message' if message_count == 1 else 'messages'}**",
|
||||||
mention_author=False,
|
mention_author=False,
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def __reload_module__():
|
|
||||||
for name, module in globals().items():
|
|
||||||
if (
|
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
|
||||||
reloaded_modules.add(name)
|
|
||||||
module.__reload_module__()
|
|
||||||
|
@ -4,18 +4,16 @@ import constants
|
|||||||
|
|
||||||
|
|
||||||
class Command(enum.Enum):
|
class Command(enum.Enum):
|
||||||
CLEAR = "clear"
|
RELOAD = "reload"
|
||||||
EXECUTE = "execute"
|
EXECUTE = "execute"
|
||||||
|
CLEAR = "clear"
|
||||||
JOIN = "join"
|
JOIN = "join"
|
||||||
LEAVE = "leave"
|
LEAVE = "leave"
|
||||||
PAUSE = "pause"
|
|
||||||
PLAY = "play"
|
|
||||||
PURGE = "purge"
|
|
||||||
QUEUE = "queue"
|
QUEUE = "queue"
|
||||||
RELOAD = "reload"
|
PLAY = "play"
|
||||||
RESUME = "resume"
|
|
||||||
SKIP = "skip"
|
SKIP = "skip"
|
||||||
UPTIME = "uptime"
|
RESUME = "resume"
|
||||||
|
PAUSE = "pause"
|
||||||
VOLUME = "volume"
|
VOLUME = "volume"
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import inspect
|
|||||||
|
|
||||||
import arguments
|
import arguments
|
||||||
import commands
|
import commands
|
||||||
import constants
|
|
||||||
import utils
|
import utils
|
||||||
import ytdlp
|
import ytdlp
|
||||||
from state import client, playback_queue, reloaded_modules
|
from state import client, playback_queue, reloaded_modules
|
||||||
@ -228,10 +227,7 @@ def generate_queue_list(queue: list):
|
|||||||
|
|
||||||
def __reload_module__():
|
def __reload_module__():
|
||||||
for name, module in globals().items():
|
for name, module in globals().items():
|
||||||
if (
|
if inspect.ismodule(module):
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||||
reloaded_modules.add(name)
|
reloaded_modules.add(name)
|
||||||
|
@ -3,9 +3,8 @@ import os
|
|||||||
EMBED_COLOR = 0xFF6600
|
EMBED_COLOR = 0xFF6600
|
||||||
OWNERS = [531392146767347712]
|
OWNERS = [531392146767347712]
|
||||||
PREFIX = "%"
|
PREFIX = "%"
|
||||||
RELOAD_BLACKLISTED_MODULES = ["re", "argparse"]
|
|
||||||
|
|
||||||
YTDL_OPTIONS = {
|
ytdl_format_options = {
|
||||||
"default_search": "auto",
|
"default_search": "auto",
|
||||||
"format": "bestaudio/best",
|
"format": "bestaudio/best",
|
||||||
"ignoreerrors": False,
|
"ignoreerrors": False,
|
||||||
@ -20,6 +19,6 @@ YTDL_OPTIONS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SECRETS = {
|
secrets = {
|
||||||
"TOKEN": os.getenv("BOT_TOKEN"),
|
"TOKEN": os.getenv("BOT_TOKEN"),
|
||||||
}
|
}
|
||||||
|
28
events.py
28
events.py
@ -23,15 +23,14 @@ async def on_message(message):
|
|||||||
|
|
||||||
if len(matched) > 1:
|
if len(matched) > 1:
|
||||||
await message.reply(
|
await message.reply(
|
||||||
f"ambiguous command, could be {' or '.join([f'`{match.value}`' for match in matched])}",
|
f"ambiguous command, could be {' or '.join(['`' + match.value + '`' for match in matched])}",
|
||||||
mention_author=False,
|
mention_author=False,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
C = commands.Command
|
|
||||||
try:
|
try:
|
||||||
match matched[0]:
|
match matched[0]:
|
||||||
case C.EXECUTE if message.author.id in constants.OWNERS:
|
case commands.Command.EXECUTE if message.author.id in constants.OWNERS:
|
||||||
code = message.content[len(tokens[0]) + 1 :].strip().strip("`")
|
code = message.content[len(tokens[0]) + 1 :].strip().strip("`")
|
||||||
for replacement in ["python", "py"]:
|
for replacement in ["python", "py"]:
|
||||||
if code.startswith(replacement):
|
if code.startswith(replacement):
|
||||||
@ -76,24 +75,22 @@ async def on_message(message):
|
|||||||
await message.add_reaction("✅")
|
await message.add_reaction("✅")
|
||||||
else:
|
else:
|
||||||
await message.channel.send(output)
|
await message.channel.send(output)
|
||||||
case C.CLEAR | C.PURGE:
|
case commands.Command.CLEAR:
|
||||||
await commands.tools.clear(message)
|
await commands.tools.clear(message)
|
||||||
case C.JOIN:
|
case commands.Command.JOIN:
|
||||||
await commands.voice.join(message)
|
await commands.voice.join(message)
|
||||||
case C.LEAVE:
|
case commands.Command.LEAVE:
|
||||||
await commands.voice.leave(message)
|
await commands.voice.leave(message)
|
||||||
case C.QUEUE | C.PLAY:
|
case commands.Command.QUEUE | commands.Command.PLAY:
|
||||||
await commands.voice.queue_or_play(message)
|
await commands.voice.queue_or_play(message)
|
||||||
case C.SKIP:
|
case commands.Command.SKIP:
|
||||||
await commands.voice.skip(message)
|
await commands.voice.skip(message)
|
||||||
case C.RESUME:
|
case commands.Command.RESUME:
|
||||||
await commands.voice.resume(message)
|
await commands.voice.resume(message)
|
||||||
case C.PAUSE:
|
case commands.Command.PAUSE:
|
||||||
await commands.voice.pause(message)
|
await commands.voice.pause(message)
|
||||||
case C.VOLUME:
|
case commands.Command.VOLUME:
|
||||||
await commands.voice.volume(message)
|
await commands.voice.volume(message)
|
||||||
case C.UPTIME:
|
|
||||||
await commands.bot.uptime(message)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await message.reply(
|
await message.reply(
|
||||||
f"exception occurred while processing command: ```\n{''.join(traceback.format_exception(e)).replace('`', '\\`')}```",
|
f"exception occurred while processing command: ```\n{''.join(traceback.format_exception(e)).replace('`', '\\`')}```",
|
||||||
@ -103,10 +100,7 @@ async def on_message(message):
|
|||||||
|
|
||||||
def __reload_module__():
|
def __reload_module__():
|
||||||
for name, module in globals().items():
|
for name, module in globals().items():
|
||||||
if (
|
if inspect.ismodule(module):
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||||
reloaded_modules.add(name)
|
reloaded_modules.add(name)
|
||||||
|
12
main.py
12
main.py
@ -2,12 +2,13 @@ import importlib
|
|||||||
import inspect
|
import inspect
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import commands
|
||||||
import constants
|
import constants
|
||||||
import core
|
import core
|
||||||
import events
|
import events
|
||||||
from state import client, reloaded_modules, start_time
|
from state import client, reloaded_modules
|
||||||
|
|
||||||
import commands
|
start_time = time.time()
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
@ -35,10 +36,7 @@ async def on_message(message):
|
|||||||
commands.Command.RELOAD
|
commands.Command.RELOAD
|
||||||
]:
|
]:
|
||||||
for name, module in globals().items():
|
for name, module in globals().items():
|
||||||
if (
|
if inspect.ismodule(module):
|
||||||
inspect.ismodule(module)
|
|
||||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
|
||||||
):
|
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||||
reloaded_modules.add(name)
|
reloaded_modules.add(name)
|
||||||
@ -50,4 +48,4 @@ async def on_message(message):
|
|||||||
await events.on_message(message)
|
await events.on_message(message)
|
||||||
|
|
||||||
|
|
||||||
client.run(constants.SECRETS["TOKEN"])
|
client.run(constants.secrets["TOKEN"])
|
||||||
|
4
state.py
4
state.py
@ -1,9 +1,5 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
start_time = time.time()
|
|
||||||
|
|
||||||
playback_queue = {}
|
playback_queue = {}
|
||||||
reloaded_modules = set()
|
reloaded_modules = set()
|
||||||
|
|
||||||
|
2
utils.py
2
utils.py
@ -14,7 +14,7 @@ async def invalid_user_handler(interaction):
|
|||||||
|
|
||||||
|
|
||||||
def filter_secrets(text: str) -> str:
|
def filter_secrets(text: str) -> str:
|
||||||
for secret_name, secret in constants.SECRETS.items():
|
for secret_name, secret in constants.secrets.items():
|
||||||
if not secret:
|
if not secret:
|
||||||
continue
|
continue
|
||||||
text = text.replace(secret, f"<{secret_name}>")
|
text = text.replace(secret, f"<{secret_name}>")
|
||||||
|
6
ytdlp.py
6
ytdlp.py
@ -9,7 +9,7 @@ import yt_dlp
|
|||||||
import constants
|
import constants
|
||||||
from state import reloaded_modules
|
from state import reloaded_modules
|
||||||
|
|
||||||
ytdl = yt_dlp.YoutubeDL(constants.YTDL_OPTIONS)
|
ytdl = yt_dlp.YoutubeDL(constants.ytdl_format_options)
|
||||||
|
|
||||||
|
|
||||||
class YTDLSource(disnake.PCMVolumeTransformer):
|
class YTDLSource(disnake.PCMVolumeTransformer):
|
||||||
@ -45,11 +45,11 @@ class YTDLSource(disnake.PCMVolumeTransformer):
|
|||||||
|
|
||||||
def __reload_module__():
|
def __reload_module__():
|
||||||
for name, module in globals().items():
|
for name, module in globals().items():
|
||||||
if inspect.ismodule(module) and name not in constants.RELOAD_BLACKLISTED_MODULES:
|
if inspect.ismodule(module):
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||||
reloaded_modules.add(name)
|
reloaded_modules.add(name)
|
||||||
module.__reload_module__()
|
module.__reload_module__()
|
||||||
|
|
||||||
global ytdl
|
global ytdl
|
||||||
ytdl = yt_dlp.YoutubeDL(constants.YTDL_OPTIONS)
|
ytdl = yt_dlp.YoutubeDL(constants.ytdl_format_options)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user