mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:17:47 +00:00
Merge branch 'dev' into command-description-config
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import asyncio
|
||||
from aioredis.client import Redis
|
||||
import discord
|
||||
from discord import ActivityType
|
||||
from discord.colour import Color
|
||||
from discord.ext import commands, tasks
|
||||
import sys
|
||||
from signal import SIGINT, SIGTERM
|
||||
import json
|
||||
from typing import Any, Dict, List, Sequence
|
||||
from discord import Message
|
||||
@@ -38,7 +36,6 @@ class ChristmasBot(commands.Bot):
|
||||
self.initial_cog_names: List[str] = self.config.get("cogs", [])
|
||||
self.colors: Dict[str, Color] = self.process_colours(config.get("colors", []))
|
||||
|
||||
|
||||
self._redis_client: Redis = aioredis.from_url(
|
||||
self.config["redis_url"], encoding="utf-8", decode_responses=True
|
||||
)
|
||||
@@ -110,6 +107,9 @@ class ChristmasBot(commands.Bot):
|
||||
await self.change_presence(activity=activity)
|
||||
|
||||
|
||||
config = json.load(open("config.json", "r", encoding="utf-8"))
|
||||
redis_prefix = config["redis_prefix"]
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
import uvloop
|
||||
@@ -119,6 +119,5 @@ if __name__ == "__main__":
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
config = json.load(open("config.json", "r", encoding="utf-8"))
|
||||
token = config.pop("token")
|
||||
ChristmasBot(config).run(token, reconnect=True)
|
||||
|
||||
+2
-4
@@ -12,6 +12,7 @@ from bot import ChristmasBot
|
||||
from utils.EmbedGenerator import EmbedGenerator
|
||||
from utils.classes import BaseCog
|
||||
from utils.paginator import HelpPaginator
|
||||
from utils.database import AutoJoin
|
||||
|
||||
|
||||
class InformationCog(BaseCog, name="Information"):
|
||||
@@ -69,10 +70,7 @@ class InformationCog(BaseCog, name="Information"):
|
||||
f"Server Uptime: `{datetime.timedelta(milliseconds=node.stats.uptime)}`"
|
||||
)
|
||||
await ctx.send(fmt)
|
||||
|
||||
from utils import database
|
||||
|
||||
database.AutoJoin.get_channels()
|
||||
AutoJoin.get_channels()
|
||||
|
||||
@commands.command(name="help", aliases=["about", "info"])
|
||||
@commands.cooldown(1, 1, commands.BucketType.user)
|
||||
|
||||
+3
-6
@@ -16,6 +16,8 @@ from utils.database import AutoJoin
|
||||
from context import CustomContext
|
||||
from discord import Embed
|
||||
|
||||
from utils.database import Playlist
|
||||
|
||||
url_rx = re.compile(r"https?://(?:www\.)?.+")
|
||||
|
||||
|
||||
@@ -105,12 +107,7 @@ class Music(BaseCog):
|
||||
await textchannel.send("Automatically joined the voice channel")
|
||||
|
||||
async def fill_player_queue(self, player: DefaultPlayer, buffer: Optional[int] = 1):
|
||||
pipeline = self.bot._redis_client.pipeline()
|
||||
for _ in range(buffer):
|
||||
pipeline.randomkey()
|
||||
|
||||
queries = await pipeline.execute()
|
||||
print(queries)
|
||||
queries = await Playlist.random(self.bot._redis_client, buffer)
|
||||
# Get the results for the query from Lavalink.
|
||||
for query in queries:
|
||||
result = await player.node.get_tracks(query)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"owner_ids": [194545408960102400, 190875175460405249],
|
||||
"prefixes": ["ck!"],
|
||||
"redis_url": "",
|
||||
"redis_prefix": "",
|
||||
"lavalink": {
|
||||
"host": "",
|
||||
"port": 2333,
|
||||
|
||||
+18
-7
@@ -1,20 +1,31 @@
|
||||
from aioredis import Redis
|
||||
from typing import Sequence
|
||||
from typing import Dict, List, Optional
|
||||
from bot import redis_prefix
|
||||
|
||||
|
||||
class AutoJoin:
|
||||
@staticmethod
|
||||
async def get_channels(redis: Redis) -> Sequence[tuple]:
|
||||
async def get_channels(redis: Redis) -> Dict[str, str]:
|
||||
# return all channels
|
||||
channels = await redis.hgetall(name="autojoin")
|
||||
channels = await redis.hgetall(f"{redis_prefix}:autojoin")
|
||||
return {key: value.split("-") for key, value in channels.items()}
|
||||
|
||||
@staticmethod
|
||||
async def update_channel(redis: Redis, guild_id, voicechannel_id, textchannel_id):
|
||||
async def update_channel(
|
||||
redis: Redis, guild_id: int, voice_channel_id: int, text_channel_id: int
|
||||
):
|
||||
await redis.hset(
|
||||
name="autojoin", key=guild_id, value=f"{voicechannel_id}-{textchannel_id}"
|
||||
f"{redis_prefix}:autojoin",
|
||||
guild_id,
|
||||
f"{voice_channel_id}-{text_channel_id}",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def del_channel(redis: Redis, guild_id):
|
||||
await redis.hdel("autojoin", guild_id)
|
||||
async def del_channel(redis: Redis, guild_id: int):
|
||||
await redis.hdel(f"{redis_prefix}:autojoin", guild_id)
|
||||
|
||||
|
||||
class Playlist:
|
||||
@staticmethod
|
||||
async def random(redis: Redis, amount: Optional[int] = 1) -> List[str]:
|
||||
return await redis.srandmember(f"{redis_prefix}:playlist", amount)
|
||||
|
||||
Reference in New Issue
Block a user