mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:07: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 List
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
import itertools
|
||||||
|
|
||||||
import aioredis
|
import aioredis
|
||||||
import discord
|
import discord
|
||||||
@@ -46,19 +47,20 @@ if len(sys.argv) > 1:
|
|||||||
config = json.load(open(config_path, "r", encoding="utf-8"))
|
config = json.load(open(config_path, "r", encoding="utf-8"))
|
||||||
redis_prefix = config["redis_prefix"]
|
redis_prefix = config["redis_prefix"]
|
||||||
colors: Dict[str, Color] = process_colours(config["colors"])
|
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):
|
class TuneBot(commands.Bot):
|
||||||
lavalink: "lavalink.Client"
|
lavalink: "lavalink.Client"
|
||||||
invite_link: str
|
invite_link: str
|
||||||
|
status_cycle = itertools.cycle(status_messages)
|
||||||
|
|
||||||
def __init__(self, config: Dict[Any, Any]):
|
def __init__(self, config: Dict[Any, Any]):
|
||||||
intents = discord.Intents(
|
intents = discord.Intents(
|
||||||
voice_states=True, guild_messages=True, guilds=True, messages=True
|
voice_states=True, guild_messages=True, guilds=True, messages=True
|
||||||
)
|
)
|
||||||
|
|
||||||
self.rpc_is_help_message = True
|
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.initial_cog_names: List[str] = self.config.get("cogs", [])
|
self.initial_cog_names: List[str] = self.config.get("cogs", [])
|
||||||
|
|
||||||
@@ -98,8 +100,8 @@ class TuneBot(commands.Bot):
|
|||||||
self.update_status.start()
|
self.update_status.start()
|
||||||
|
|
||||||
async def prefix_callable(self, _, msg: Message):
|
async def prefix_callable(self, _, msg: Message):
|
||||||
logger.info(f"{self.config['prefixes']=}")
|
logger.info(f"{self.config['prefix']=}")
|
||||||
return commands.when_mentioned_or(*self.config["prefixes"])(self, msg)
|
return commands.when_mentioned_or(self.config["prefix"])(self, msg)
|
||||||
|
|
||||||
async def load_cogs(self, cog_names: Sequence[str]):
|
async def load_cogs(self, cog_names: Sequence[str]):
|
||||||
for cog in cog_names:
|
for cog in cog_names:
|
||||||
@@ -146,18 +148,11 @@ class TuneBot(commands.Bot):
|
|||||||
def playlist_source_context(self, ctx: "ContextLike") -> "PlaylistSource":
|
def playlist_source_context(self, ctx: "ContextLike") -> "PlaylistSource":
|
||||||
return RedisPlaylistSource(ctx)
|
return RedisPlaylistSource(ctx)
|
||||||
|
|
||||||
@tasks.loop(seconds=30)
|
@tasks.loop(seconds=status_interval)
|
||||||
async def update_status(self):
|
async def update_status(self):
|
||||||
await self.wait_until_ready()
|
await self.wait_until_ready()
|
||||||
|
name = next(self.status_cycle)
|
||||||
bot_prefix = self.config["prefixes"][0]
|
activity = discord.Activity(name=name, type=ActivityType.listening)
|
||||||
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
|
|
||||||
await self.change_presence(activity=activity)
|
await self.change_presence(activity=activity)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -5,9 +5,7 @@
|
|||||||
190875175460405250
|
190875175460405250
|
||||||
],
|
],
|
||||||
"manager_ids": [],
|
"manager_ids": [],
|
||||||
"prefixes": [
|
"prefix": "ck!",
|
||||||
"ck!"
|
|
||||||
],
|
|
||||||
"redis_url": "",
|
"redis_url": "",
|
||||||
"redis_prefix": "",
|
"redis_prefix": "",
|
||||||
"lavalink": {
|
"lavalink": {
|
||||||
@@ -22,7 +20,14 @@
|
|||||||
},
|
},
|
||||||
"info": {
|
"info": {
|
||||||
"name": "CloudKid Radio",
|
"name": "CloudKid Radio",
|
||||||
"description": "A sample bot description"
|
"description": "A sample bot description",
|
||||||
|
"status": {
|
||||||
|
"messages": [
|
||||||
|
"bangers",
|
||||||
|
"noises 🤖"
|
||||||
|
],
|
||||||
|
"interval": 12
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"cogs": [
|
"cogs": [
|
||||||
"jishaku",
|
"jishaku",
|
||||||
|
|||||||
Reference in New Issue
Block a user