mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:57:48 +00:00
Bot status is now more customizable
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import Dict
|
||||
from typing import List
|
||||
from typing import Sequence
|
||||
from typing import TYPE_CHECKING
|
||||
import itertools
|
||||
|
||||
import aioredis
|
||||
import discord
|
||||
@@ -46,19 +47,20 @@ if len(sys.argv) > 1:
|
||||
config = json.load(open(config_path, "r", encoding="utf-8"))
|
||||
redis_prefix = config["redis_prefix"]
|
||||
colors: Dict[str, Color] = process_colours(config["colors"])
|
||||
status_messages: Sequence[str] = config["info"]["status"]["messages"]
|
||||
status_interval: int = config["info"]["status"]["interval"]
|
||||
|
||||
|
||||
class TuneBot(commands.Bot):
|
||||
lavalink: "lavalink.Client"
|
||||
invite_link: str
|
||||
status_cycle = itertools.cycle(status_messages)
|
||||
|
||||
def __init__(self, config: Dict[Any, Any]):
|
||||
intents = discord.Intents(
|
||||
voice_states=True, guild_messages=True, guilds=True, messages=True
|
||||
)
|
||||
|
||||
self.rpc_is_help_message = True
|
||||
|
||||
self.config = config
|
||||
self.initial_cog_names: List[str] = self.config.get("cogs", [])
|
||||
|
||||
@@ -98,8 +100,8 @@ class TuneBot(commands.Bot):
|
||||
self.update_status.start()
|
||||
|
||||
async def prefix_callable(self, _, msg: Message):
|
||||
logger.info(f"{self.config['prefixes']=}")
|
||||
return commands.when_mentioned_or(*self.config["prefixes"])(self, msg)
|
||||
logger.info(f"{self.config['prefix']=}")
|
||||
return commands.when_mentioned_or(self.config["prefix"])(self, msg)
|
||||
|
||||
async def load_cogs(self, cog_names: Sequence[str]):
|
||||
for cog in cog_names:
|
||||
@@ -146,18 +148,11 @@ class TuneBot(commands.Bot):
|
||||
def playlist_source_context(self, ctx: "ContextLike") -> "PlaylistSource":
|
||||
return RedisPlaylistSource(ctx)
|
||||
|
||||
@tasks.loop(seconds=30)
|
||||
@tasks.loop(seconds=status_interval)
|
||||
async def update_status(self):
|
||||
await self.wait_until_ready()
|
||||
|
||||
bot_prefix = self.config["prefixes"][0]
|
||||
if self.rpc_is_help_message:
|
||||
title = f"for {bot_prefix}connect | {bot_prefix}help"
|
||||
activity = discord.Activity(name=title, type=ActivityType.watching)
|
||||
else:
|
||||
activity = discord.Activity(name="Some song", type=ActivityType.playing)
|
||||
|
||||
self.rpc_is_help_message = not self.rpc_is_help_message
|
||||
name = next(self.status_cycle)
|
||||
activity = discord.Activity(name=name, type=ActivityType.listening)
|
||||
await self.change_presence(activity=activity)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user