mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:07:48 +00:00
Merge branch 'dev' into lavalink-functionality
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
|
import asyncio
|
||||||
|
from aioredis.client import Redis
|
||||||
import discord
|
import discord
|
||||||
|
from discord import ActivityType
|
||||||
from discord.colour import Color
|
from discord.colour import Color
|
||||||
from discord.ext import commands
|
from discord.ext import commands, tasks
|
||||||
import sys
|
import sys
|
||||||
|
from signal import SIGINT, SIGTERM
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Sequence
|
from typing import Any, Dict, List, Sequence
|
||||||
from discord import Message
|
from discord import Message
|
||||||
@@ -12,6 +16,10 @@ from discord.ext.commands.errors import (
|
|||||||
NoEntryPointError,
|
NoEntryPointError,
|
||||||
)
|
)
|
||||||
import lavalink
|
import lavalink
|
||||||
|
import aioredis
|
||||||
|
from aioredis import Redis
|
||||||
|
|
||||||
|
from context import CustomContext
|
||||||
|
|
||||||
|
|
||||||
class ChristmasBot(commands.Bot):
|
class ChristmasBot(commands.Bot):
|
||||||
@@ -23,18 +31,31 @@ class ChristmasBot(commands.Bot):
|
|||||||
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.update_status.start()
|
||||||
|
|
||||||
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", [])
|
||||||
self.colors: Dict[str, Color] = self.process_colours(config.get("colors", []))
|
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
|
||||||
|
)
|
||||||
|
self.invite_link: str = ""
|
||||||
|
|
||||||
|
slash_guilds = None
|
||||||
|
if len(self.config["slash_command_guilds"]) > 0:
|
||||||
|
slash_guilds = self.config["slash_command_guilds"]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
command_prefix=self.prefix_callable,
|
command_prefix=self.prefix_callable,
|
||||||
description=self.config["info"].get("description", ""),
|
description=self.config["info"]["description"],
|
||||||
case_insensitive=False,
|
case_insensitive=False,
|
||||||
fetch_offline_members=False,
|
fetch_offline_members=False,
|
||||||
intents=intents,
|
intents=intents,
|
||||||
slash_commands=True,
|
slash_commands=True,
|
||||||
slash_command_guilds=[227431704426446848],
|
slash_command_guilds=slash_guilds,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.loop.create_task(self.async_init())
|
self.loop.create_task(self.async_init())
|
||||||
@@ -71,6 +92,23 @@ class ChristmasBot(commands.Bot):
|
|||||||
colour_dict[name] = Color(int(color, 16))
|
colour_dict[name] = Color(int(color, 16))
|
||||||
return colour_dict
|
return colour_dict
|
||||||
|
|
||||||
|
async def get_context(self, message: Message, *, cls=CustomContext):
|
||||||
|
return await super().get_context(message, cls=cls)
|
||||||
|
|
||||||
|
@tasks.loop(seconds=30)
|
||||||
|
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
|
||||||
|
await self.change_presence(activity=activity)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
|
|||||||
+4
-16
@@ -6,24 +6,14 @@ from discord.ext.commands import Context
|
|||||||
import humanize
|
import humanize
|
||||||
import datetime
|
import datetime
|
||||||
import lavalink
|
import lavalink
|
||||||
|
from bot import ChristmasBot
|
||||||
from utils.EmbedGenerator import EmbedGenerator
|
from utils.EmbedGenerator import EmbedGenerator
|
||||||
from utils.paginator import HelpPaginator
|
from utils.paginator import HelpPaginator
|
||||||
|
|
||||||
|
|
||||||
class InformationCog(commands.Cog, name="Information"):
|
class InformationCog(commands.Cog, name="Information"):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: ChristmasBot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.is_help_msg = True
|
|
||||||
self.update_status.start()
|
|
||||||
|
|
||||||
@tasks.loop(seconds=30.0)
|
|
||||||
async def update_status(self):
|
|
||||||
await self.bot.wait_until_ready()
|
|
||||||
title = "ck!connect | ck!help"
|
|
||||||
if self.is_help_msg:
|
|
||||||
title = "Tfoe broer"
|
|
||||||
self.is_help_msg = not self.is_help_msg
|
|
||||||
await self.bot.change_presence(activity=discord.Game(title))
|
|
||||||
|
|
||||||
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
|
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
|
||||||
@commands.command(description="PONG!", aliases=["pong"])
|
@commands.command(description="PONG!", aliases=["pong"])
|
||||||
@@ -53,9 +43,7 @@ class InformationCog(commands.Cog, name="Information"):
|
|||||||
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
|
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
|
||||||
async def invite(self, ctx: Context):
|
async def invite(self, ctx: Context):
|
||||||
"""Gets the invite link!"""
|
"""Gets the invite link!"""
|
||||||
link = f"https://discord.com/oauth2/authorize?client_id=643555373814382593&permissions=3230720&scope=bot%20applications.commands"
|
await EmbedGenerator.Message(ctx, "Add our bot to your server:", self.bot.invite_link)
|
||||||
embed = await EmbedGenerator.Message(ctx, "Add our bot to your server:", link)
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
name="wlinfo",
|
name="wlinfo",
|
||||||
@@ -129,6 +117,6 @@ class InformationCog(commands.Cog, name="Information"):
|
|||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: ChristmasBot):
|
||||||
bot.remove_command("help")
|
bot.remove_command("help")
|
||||||
bot.add_cog(InformationCog(bot))
|
bot.add_cog(InformationCog(bot))
|
||||||
|
|||||||
+3
-8
@@ -2,13 +2,7 @@
|
|||||||
"token": "",
|
"token": "",
|
||||||
"owner_ids": [194545408960102400, 190875175460405249],
|
"owner_ids": [194545408960102400, 190875175460405249],
|
||||||
"prefixes": ["ck!"],
|
"prefixes": ["ck!"],
|
||||||
"database": {
|
"redis_url": "",
|
||||||
"host": "",
|
|
||||||
"port": 3306,
|
|
||||||
"user": "",
|
|
||||||
"password": "",
|
|
||||||
"db": ""
|
|
||||||
},
|
|
||||||
"lavalink": {
|
"lavalink": {
|
||||||
"host": "",
|
"host": "",
|
||||||
"port": 2333,
|
"port": 2333,
|
||||||
@@ -23,5 +17,6 @@
|
|||||||
"name": "CloudKid Radio",
|
"name": "CloudKid Radio",
|
||||||
"description": "A sample bot description"
|
"description": "A sample bot description"
|
||||||
},
|
},
|
||||||
"cogs": ["cogs.owner", "cogs.settings", "cogs.information", "cogs.music"]
|
"cogs": ["cogs.owner", "cogs.settings", "cogs.information", "cogs.music"],
|
||||||
|
"slash_command_guilds": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from aioredis.client import Redis
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class CustomContext(commands.Context):
|
||||||
|
def get_redis(self) -> Redis:
|
||||||
|
return self.bot._redis_client
|
||||||
Generated
+21
-2
@@ -16,6 +16,21 @@ yarl = ">=1.0,<1.6.0"
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
speedups = ["aiodns", "brotlipy", "cchardet"]
|
speedups = ["aiodns", "brotlipy", "cchardet"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aioredis"
|
||||||
|
version = "2.0.0"
|
||||||
|
description = "asyncio (PEP 3156) Redis support"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
async-timeout = "*"
|
||||||
|
typing-extensions = "*"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
hiredis = ["hiredis (>=1.0)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-timeout"
|
name = "async-timeout"
|
||||||
version = "3.0.1"
|
version = "3.0.1"
|
||||||
@@ -258,7 +273,7 @@ python-versions = ">=3.6"
|
|||||||
name = "typing-extensions"
|
name = "typing-extensions"
|
||||||
version = "3.10.0.2"
|
version = "3.10.0.2"
|
||||||
description = "Backported and Experimental Type Hints for Python 3.5+"
|
description = "Backported and Experimental Type Hints for Python 3.5+"
|
||||||
category = "dev"
|
category = "main"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "*"
|
python-versions = "*"
|
||||||
|
|
||||||
@@ -290,7 +305,7 @@ multidict = ">=4.0"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.8"
|
python-versions = "^3.8"
|
||||||
content-hash = "9ecfdbfb13478abd79ab060516a2001a0706019f52c946f63e5ebb308e01622f"
|
content-hash = "3e8f3b5171be334aaa606cd70df03f9b0ac49cb2f78b69723ff49233ce9c1cd3"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiohttp = [
|
aiohttp = [
|
||||||
@@ -308,6 +323,10 @@ aiohttp = [
|
|||||||
{file = "aiohttp-3.6.3-cp37-cp37m-win_amd64.whl", hash = "sha256:687461cd974722110d1763b45c5db4d2cdee8d50f57b00c43c7590d1dd77fc5c"},
|
{file = "aiohttp-3.6.3-cp37-cp37m-win_amd64.whl", hash = "sha256:687461cd974722110d1763b45c5db4d2cdee8d50f57b00c43c7590d1dd77fc5c"},
|
||||||
{file = "aiohttp-3.6.3.tar.gz", hash = "sha256:698cd7bc3c7d1b82bb728bae835724a486a8c376647aec336aa21a60113c3645"},
|
{file = "aiohttp-3.6.3.tar.gz", hash = "sha256:698cd7bc3c7d1b82bb728bae835724a486a8c376647aec336aa21a60113c3645"},
|
||||||
]
|
]
|
||||||
|
aioredis = [
|
||||||
|
{file = "aioredis-2.0.0-py3-none-any.whl", hash = "sha256:9921d68a3df5c5cdb0d5b49ad4fc88a4cfdd60c108325df4f0066e8410c55ffb"},
|
||||||
|
{file = "aioredis-2.0.0.tar.gz", hash = "sha256:3a2de4b614e6a5f8e104238924294dc4e811aefbe17ddf52c04a93cbf06e67db"},
|
||||||
|
]
|
||||||
async-timeout = [
|
async-timeout = [
|
||||||
{file = "async-timeout-3.0.1.tar.gz", hash = "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f"},
|
{file = "async-timeout-3.0.1.tar.gz", hash = "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f"},
|
||||||
{file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"},
|
{file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"},
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ lavalink = "^3.1.4"
|
|||||||
humanize = "^3.12.0"
|
humanize = "^3.12.0"
|
||||||
"discord.py" = { git = "https://github.com/iDevision/enhanced-discord.py", branch = "2.0", extras = ["voice", "speed"] }
|
"discord.py" = { git = "https://github.com/iDevision/enhanced-discord.py", branch = "2.0", extras = ["voice", "speed"] }
|
||||||
uvloop = {version = "^0.16.0", optional = true}
|
uvloop = {version = "^0.16.0", optional = true}
|
||||||
|
aioredis = "^2.0.0"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
black = {version = "^21.9b0", allow-prereleases = true}
|
black = {version = "^21.9b0", allow-prereleases = true}
|
||||||
|
|||||||
Reference in New Issue
Block a user