mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
small PR adding [p]llset info and [p]audioset logs (#4527)
* small PR adding `[p]llset info` and `[p]audioset logs` * fixed + improvements * Zip file properly
This commit is contained in:
parent
18986bcc42
commit
38169a82df
@ -1,6 +1,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import tarfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
@ -18,7 +20,7 @@ from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate
|
|||||||
from ...audio_dataclasses import LocalPath
|
from ...audio_dataclasses import LocalPath
|
||||||
from ...converters import ScopeParser
|
from ...converters import ScopeParser
|
||||||
from ...errors import MissingGuild, TooManyMatches
|
from ...errors import MissingGuild, TooManyMatches
|
||||||
from ...utils import CacheLevel, PlaylistScope
|
from ...utils import CacheLevel, PlaylistScope, has_internal_server
|
||||||
from ..abc import MixinMeta
|
from ..abc import MixinMeta
|
||||||
from ..cog_utils import CompositeMetaClass, PlaylistConverter, __version__
|
from ..cog_utils import CompositeMetaClass, PlaylistConverter, __version__
|
||||||
|
|
||||||
@ -1129,6 +1131,47 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
|
|||||||
|
|
||||||
await self.send_embed_msg(ctx, description=box(msg, lang="ini"))
|
await self.send_embed_msg(ctx, description=box(msg, lang="ini"))
|
||||||
|
|
||||||
|
@command_audioset.command(name="logs")
|
||||||
|
@commands.is_owner()
|
||||||
|
@has_internal_server()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def command_audioset_logs(self, ctx: commands.Context):
|
||||||
|
"""Sends the Lavalink server logs to your DMs."""
|
||||||
|
datapath = cog_data_path(raw_name="Audio")
|
||||||
|
logs = datapath / "logs" / "spring.log"
|
||||||
|
zip_name = None
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
if not (logs.exists() and logs.is_file()):
|
||||||
|
return await ctx.send(_("No logs found in your data folder."))
|
||||||
|
except OSError:
|
||||||
|
return await ctx.send(_("No logs found in your data folder."))
|
||||||
|
|
||||||
|
def check(path):
|
||||||
|
return os.path.getsize(str(path)) > (8388608 - 1000)
|
||||||
|
|
||||||
|
if check(logs):
|
||||||
|
zip_name = logs.with_suffix(".tar.gz")
|
||||||
|
zip_name.unlink(missing_ok=True)
|
||||||
|
with tarfile.open(zip_name, "w:gz") as tar:
|
||||||
|
tar.add(str(logs), arcname="spring.log", recursive=False)
|
||||||
|
if check(zip_name):
|
||||||
|
await ctx.send(
|
||||||
|
_("Logs are too large, you can find them in {path}").format(
|
||||||
|
path=zip_name.absolute()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
zip_name = None
|
||||||
|
else:
|
||||||
|
await ctx.author.send(file=discord.File(str(zip_name)))
|
||||||
|
else:
|
||||||
|
await ctx.author.send(file=discord.File(str(logs)))
|
||||||
|
except discord.HTTPException:
|
||||||
|
await ctx.send(_("I need to be able to DM you to send you the logs."))
|
||||||
|
finally:
|
||||||
|
if zip_name is not None:
|
||||||
|
zip_name.unlink(missing_ok=True)
|
||||||
|
|
||||||
@command_audioset.command(name="status")
|
@command_audioset.command(name="status")
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import discord
|
|||||||
|
|
||||||
from redbot.core import commands
|
from redbot.core import commands
|
||||||
from redbot.core.i18n import Translator
|
from redbot.core.i18n import Translator
|
||||||
|
from redbot.core.utils.chat_formatting import box
|
||||||
|
|
||||||
from ..abc import MixinMeta
|
from ..abc import MixinMeta
|
||||||
from ..cog_utils import CompositeMetaClass
|
from ..cog_utils import CompositeMetaClass
|
||||||
@ -236,3 +237,21 @@ class LavalinkSetupCommands(MixinMeta, metaclass=CompositeMetaClass):
|
|||||||
prefix=ctx.prefix
|
prefix=ctx.prefix
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@command_llsetup.command(name="info", aliases=["settings"])
|
||||||
|
async def command_llsetup_info(self, ctx: commands.Context):
|
||||||
|
"""Display Lavalink connection settings."""
|
||||||
|
configs = await self.config.all()
|
||||||
|
host = configs["host"]
|
||||||
|
password = configs["password"]
|
||||||
|
rest_port = configs["rest_port"]
|
||||||
|
ws_port = configs["ws_port"]
|
||||||
|
msg = "----" + _("Connection Settings") + "---- \n"
|
||||||
|
msg += _("Host: [{host}]\n").format(host=host)
|
||||||
|
msg += _("Rest Port: [{port}]\n").format(port=rest_port)
|
||||||
|
msg += _("WS Port: [{port}]\n").format(port=ws_port)
|
||||||
|
msg += _("Password: [{password}]\n").format(password=password)
|
||||||
|
try:
|
||||||
|
await self.send_embed_msg(ctx.author, description=box(msg, lang="ini"))
|
||||||
|
except discord.HTTPException:
|
||||||
|
await ctx.send(_("I need to be able to DM you to send you this info."))
|
||||||
|
|||||||
@ -220,3 +220,11 @@ def task_callback(task: asyncio.Task) -> None:
|
|||||||
with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError):
|
with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError):
|
||||||
if exc := task.exception():
|
if exc := task.exception():
|
||||||
log.exception(f"{task.get_name()} raised an Exception", exc_info=exc)
|
log.exception(f"{task.get_name()} raised an Exception", exc_info=exc)
|
||||||
|
|
||||||
|
|
||||||
|
def has_internal_server():
|
||||||
|
async def pred(ctx: commands.Context):
|
||||||
|
external = await ctx.cog.config.use_external_lavalink()
|
||||||
|
return not external
|
||||||
|
|
||||||
|
return commands.check(pred)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user