mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
Use yaml for settings.
This commit is contained in:
1 parent
e8225d42f0
commit
2cc4d9771a
10 files changed
+68
-53
No files matched your search
+2
-4
@@ -1,7 +1,5 @@
|
||||
config.json
|
||||
data/
|
||||
lavalink/
|
||||
lavasettings.py
|
||||
data/*
|
||||
!data/config.yaml.example
|
||||
.tests/
|
||||
.idea/
|
||||
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import json
|
||||
import codecs
|
||||
import discord
|
||||
import codecs
|
||||
import time
|
||||
import sys
|
||||
import traceback
|
||||
import yaml
|
||||
|
||||
from discord.ext import commands
|
||||
from cogs.utils.settings import Settings
|
||||
|
||||
from cogs.utils.localizer import Localizer
|
||||
|
||||
initial_extension = [
|
||||
|
||||
initial_extensions = [
|
||||
'cogs.cogs',
|
||||
'cogs.botsettings',
|
||||
'cogs.misc'
|
||||
]
|
||||
|
||||
|
||||
with codecs.open("config.json", 'r', encoding='utf8') as f:
|
||||
config = json.load(f)
|
||||
|
||||
default_prefix = config["default_prefix"]
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.safe_load(f)
|
||||
|
||||
|
||||
def _get_prefix(bot, message):
|
||||
@@ -33,14 +31,13 @@ def _get_prefix(bot, message):
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self, debug: bool=False):
|
||||
super().__init__(command_prefix=_get_prefix,
|
||||
description=config["description"])
|
||||
description=conf["bot"]["description"])
|
||||
|
||||
self.settings = Settings(**config)
|
||||
# Todo, maybe fix. Ability to set default bot lang in settings
|
||||
self.localizer = Localizer(self.settings.default_lang_path, "en_en")
|
||||
self.settings = Settings(**conf['default server settings'])
|
||||
self.localizer = Localizer(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
|
||||
self.debug = debug
|
||||
|
||||
for extension in initial_extension:
|
||||
for extension in initial_extensions:
|
||||
try:
|
||||
self.load_extension(extension)
|
||||
except Exception as e:
|
||||
@@ -92,12 +89,12 @@ class Bot(commands.Bot):
|
||||
self.load_extension('cogs.musicevents')
|
||||
|
||||
await self.change_presence(activity=discord.Game(type=0,
|
||||
name=config["playing"]),
|
||||
name=conf["bot"]["playing status"]),
|
||||
status=discord.Status.online)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
super().run(config["token"], reconnect=True)
|
||||
super().run(conf["bot"]["token"], reconnect=True)
|
||||
except Exception as e:
|
||||
tb = e.__traceback__
|
||||
traceback.print_tb(tb)
|
||||
|
||||
@@ -129,7 +129,6 @@ class BotSettings:
|
||||
@commands.guild_only()
|
||||
@_set.command(name='djroles')
|
||||
async def set_dj_roles(self, ctx, *roles: discord.Role):
|
||||
print(roles)
|
||||
role_ids = [role.id for role in roles]
|
||||
if roles:
|
||||
self.bot.settings.set(ctx.guild.id, 'roles.dj', role_ids)
|
||||
|
||||
+12
-9
@@ -4,19 +4,18 @@ Music commands
|
||||
import math
|
||||
import re
|
||||
import asyncio
|
||||
|
||||
import discord
|
||||
import lavalink
|
||||
from discord.ext import commands
|
||||
import time
|
||||
import yaml
|
||||
import codecs
|
||||
|
||||
import lavalink
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from typing import Optional
|
||||
|
||||
from .utils import checks, RoxUtils
|
||||
from .utils.mixplayer import MixPlayer
|
||||
from typing import Optional
|
||||
|
||||
from .utils.embedscroller import QueueScroller
|
||||
from lavasettings import *
|
||||
|
||||
from .utils.localizer import LocalizerWrapper
|
||||
|
||||
time_rx = re.compile('[0-9]+')
|
||||
@@ -29,7 +28,11 @@ class Music:
|
||||
|
||||
if not hasattr(bot, 'lavalink'): # This ensures the client isn't overwritten during cog reloads.
|
||||
bot.lavalink = lavalink.Client(bot.user.id, player=MixPlayer)
|
||||
bot.lavalink.add_node(host, port, password, region, 'default-node') # Host, Port, Password, Region, Name
|
||||
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.safe_load(f)
|
||||
|
||||
bot.lavalink.add_node(**conf['lavalink nodes']['main'])
|
||||
bot.add_listener(bot.lavalink.voice_update_handler, 'on_socket_response')
|
||||
|
||||
def getLocalizer(self, guild_id):
|
||||
|
||||
+6
-4
@@ -3,7 +3,7 @@ A cog to separate events from regular music commands
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
import yaml
|
||||
import discord
|
||||
import lavalink
|
||||
from discord.ext import commands
|
||||
@@ -12,8 +12,6 @@ import time
|
||||
from .utils.mixplayer import MixPlayer
|
||||
from lavalink.events import *
|
||||
|
||||
from lavasettings import *
|
||||
|
||||
|
||||
class MusicEvents:
|
||||
def __init__(self, bot):
|
||||
@@ -21,7 +19,11 @@ class MusicEvents:
|
||||
# TODO: maybe only load when Music loads
|
||||
if not hasattr(bot, 'lavalink'): # This ensures the client isn't overwritten during cog reloads.
|
||||
bot.lavalink = lavalink.Client(bot.user.id, player=MixPlayer)
|
||||
bot.lavalink.add_node(host, port, password, region, 'default-node') # Host, Port, Password, Region, Name
|
||||
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.safe_load(f)
|
||||
|
||||
bot.lavalink.add_node(**conf['lavalink nodes']['main'])
|
||||
bot.add_listener(bot.lavalink.voice_update_handler, 'on_socket_response')
|
||||
|
||||
bot.lavalink.add_event_hook(self.track_hook)
|
||||
|
||||
@@ -9,12 +9,10 @@ class Settings:
|
||||
self._DATA_PATH = 'data/bot/'
|
||||
self._SETTINGS_PATH = self._DATA_PATH + 'settings.json'
|
||||
|
||||
self.default_prefix = default_settings["default_prefix"]
|
||||
self.default_admin = default_settings["default_admin"]
|
||||
self.default_mod = default_settings["default_mod"]
|
||||
self.default_locale = default_settings["default_locale"]
|
||||
self.default_lang_path = default_settings["default_lang_path"] or \
|
||||
"./localization"
|
||||
self.default_prefix = default_settings["prefix"]
|
||||
self.default_mod = default_settings["moderator_role"]
|
||||
self.default_locale = default_settings["locale"]
|
||||
self.default_threshold = default_settings["threshold"]
|
||||
|
||||
if not self.default_locale:
|
||||
locale, codepage = locale.getlocale()
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"token": "",
|
||||
"default_prefix": [""],
|
||||
"default_admin": "Admin",
|
||||
"default_mod": "Moderator",
|
||||
"default_locale": "en_en",
|
||||
"default_lang_path": "./localization",
|
||||
"playing": "",
|
||||
"description": ""
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
bot:
|
||||
token:
|
||||
description: Music bot
|
||||
playing status: music
|
||||
|
||||
# Where the bot will look for translations
|
||||
locale_path: ./localization
|
||||
|
||||
# Settings used if server settings aren't specified
|
||||
default server settings:
|
||||
prefix:
|
||||
- "!"
|
||||
moderator_role: Moderator
|
||||
locale: en_en
|
||||
threshold: 50
|
||||
|
||||
lavalink nodes:
|
||||
main: # The preferred lavalink node for your music bot
|
||||
host: localhost
|
||||
port: 2333
|
||||
password: youshallnotpass
|
||||
region: eu
|
||||
name: default-node
|
||||
|
||||
# Backup nodes for your music bot
|
||||
backup:
|
||||
- host: localhost
|
||||
port: 2333
|
||||
password: youshallnotpass
|
||||
region: eu
|
||||
name: backup-1
|
||||
@@ -1,4 +0,0 @@
|
||||
host = 'localhost'
|
||||
port = 2333
|
||||
password = 'youshallnotpass'
|
||||
region = 'eu'
|
||||
@@ -1,5 +1,6 @@
|
||||
git+https://github.com/Rapptz/discord.py@rewrite
|
||||
git+https://github.com/Devoxin/Lavalink.py@dev
|
||||
asyncio
|
||||
pyyaml
|
||||
bs4
|
||||
aiohttp<3.5.0,>=3.3.0
|
||||
Reference in new issue
Block a user