mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
Feature/new docker (#17)
* Run arguments Introduced self.bot.datafolder * Improved container Utilizing the new run-args * Better tagging * Consistency
This commit is contained in:
1 parent
f898dd7582
commit
cc4bf974c1
7 files changed
+42
-25
No files matched your search
+1
-1
@@ -11,6 +11,6 @@ RUN \
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ln -sf /app/data /config && /app/localization /config && python3 /app/bot.py
|
||||
CMD cp -u /app/data/config.yaml.example /config/config.yaml.example && python3 /app/bot.py --data-directory /config
|
||||
|
||||
VOLUME /config
|
||||
Vendored
+4
-3
@@ -16,6 +16,7 @@ pipeline {
|
||||
"""
|
||||
script {
|
||||
TAG = sh(returnStdout: true, script: 'grep -i bot_version cogs/utils/bot_version.py | cut -d" " -f3 | tr -d \\"').trim()
|
||||
SBranch = sh(returnStdout: true, script: 'echo ${GIT_BRANCH} | sed "s#/#_#"').trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,10 +32,10 @@ pipeline {
|
||||
steps {
|
||||
script {
|
||||
if (BRANCH_NAME == 'master') {
|
||||
def image = docker.build("${DOCKER_REPO}:${TAG}")
|
||||
def image = docker.build("${DOCKER_REPO}:${TAG}-amd64")
|
||||
image.push()
|
||||
}
|
||||
def image = docker.build("${DOCKER_REPO}:$GIT_BRANCH")
|
||||
def image = docker.build("${DOCKER_REPO}:${SBranch}-amd64")
|
||||
image.push()
|
||||
}
|
||||
}
|
||||
@@ -46,7 +47,7 @@ pipeline {
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def image = docker.build("${DOCKER_REPO}:PR_$GIT_BRANCH")
|
||||
def image = docker.build("${DOCKER_REPO}:PR_$GIT_BRANCH-amd64")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import discord
|
||||
import codecs
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import traceback
|
||||
import yaml
|
||||
import aiohttp
|
||||
|
||||
from discord.ext import commands
|
||||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
from cogs.utils.settingsmanager import Settings
|
||||
from cogs.utils.localizer import Localizer
|
||||
from cogs.utils.localizer import LocalizerWrapper
|
||||
@@ -16,11 +17,6 @@ from cogs.utils.logger import BotLogger
|
||||
from cogs.helpformatter import commandhelper
|
||||
from cogs.utils.paginator import Scroller
|
||||
|
||||
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.load(f, Loader=yaml.SafeLoader)
|
||||
|
||||
|
||||
initial_extensions = [
|
||||
'cogs.cogs',
|
||||
'cogs.settings',
|
||||
@@ -28,7 +24,6 @@ initial_extensions = [
|
||||
'cogs.helpformatter'
|
||||
]
|
||||
|
||||
|
||||
on_ready_extensions = [
|
||||
'cogs.music',
|
||||
'cogs.musicevents'
|
||||
@@ -44,11 +39,11 @@ def _get_prefix(bot, message):
|
||||
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self, debug: bool = False):
|
||||
def __init__(self, datadir, debug: bool = False):
|
||||
super().__init__(command_prefix=_get_prefix,
|
||||
description=conf["bot"]["description"])
|
||||
|
||||
self.settings = Settings(**conf['default server settings'])
|
||||
self.settings = Settings(datadir, **conf['default server settings'])
|
||||
self.APIkeys = conf.get('APIkeys', {})
|
||||
|
||||
self.localizer = Localizer(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
|
||||
@@ -56,6 +51,7 @@ class Bot(commands.Bot):
|
||||
|
||||
self.session = aiohttp.ClientSession(loop=self.loop)
|
||||
|
||||
self.datadir = datadir
|
||||
self.debug = debug
|
||||
self.main_logger = logger
|
||||
self.logger = self.main_logger.bot_logger.getChild("Bot")
|
||||
@@ -150,14 +146,34 @@ class Bot(commands.Bot):
|
||||
print(e)
|
||||
|
||||
|
||||
def run_bot(debug: bool = False):
|
||||
bot = Bot(debug=debug)
|
||||
def run_bot(datadir, debug: bool = False):
|
||||
bot = Bot(datadir, debug=debug)
|
||||
bot.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
state = False
|
||||
if 'debug' in sys.argv:
|
||||
state = True
|
||||
logger = BotLogger(state, conf.get('log_path', './data/logs'))
|
||||
run_bot(debug=state)
|
||||
parser = ArgumentParser(prog='Shite Music Bot',
|
||||
description='Discord music bot utilizing discord.py, lavalink and lavalink.py',
|
||||
formatter_class=RawTextHelpFormatter)
|
||||
|
||||
parser.add_argument("-D", "--debug", action='store_true', help='Sets debug to true')
|
||||
parser.add_argument("-d", "--data-directory", help='Define an alternate data directory location')
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.debug or os.environ.get('debug'):
|
||||
is_debug = True
|
||||
else:
|
||||
is_debug = False
|
||||
|
||||
if args.data_folder:
|
||||
datadir = str(args.data_folder)
|
||||
else:
|
||||
datadir = "data"
|
||||
|
||||
print(f"Data folder: {datadir}")
|
||||
|
||||
with codecs.open(f"{datadir}/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.load(f, Loader=yaml.SafeLoader)
|
||||
|
||||
logger = BotLogger(is_debug, conf.get('log_path', f'{datadir}/logs'))
|
||||
run_bot(debug=is_debug, datadir=datadir)
|
||||
+1
-1
@@ -32,7 +32,7 @@ class Music(commands.Cog):
|
||||
if not hasattr(bot, 'lavalink'): # This ensures the client isn't overwritten during cog reloads.
|
||||
bot.lavalink = lavalink.Client(bot.user.id, player=MixPlayer)
|
||||
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
with codecs.open(f"{self.bot.datadir}/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.load(f, Loader=yaml.SafeLoader)
|
||||
|
||||
bot.lavalink.add_node(**conf['lavalink nodes']['main'])
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ class MusicEvents(commands.Cog):
|
||||
if not hasattr(bot, 'lavalink'): # This ensures the client isn't overwritten during cog reloads.
|
||||
bot.lavalink = lavalink.Client(bot.user.id, player=MixPlayer)
|
||||
|
||||
with codecs.open("data/config.yaml", 'r', encoding='utf8') as f:
|
||||
with codecs.open(f"{self.bot.datadir}/config.yaml", 'r', encoding='utf8') as f:
|
||||
conf = yaml.load(f, Loader=yaml.SafeLoader)
|
||||
|
||||
bot.lavalink.add_node(**conf['lavalink nodes']['main'])
|
||||
|
||||
@@ -24,7 +24,7 @@ class BotLogger(object):
|
||||
os.makedirs(self.log_location)
|
||||
print(f"Creating logging directory: {self.log_location}")
|
||||
if self.log_level:
|
||||
print(os.path.abspath(self.log_location))
|
||||
print(f"Logging directory: {self.log_location}")
|
||||
file_logger = logging.handlers.RotatingFileHandler(f'{self.log_location}/bot.log', mode='a',
|
||||
maxBytes=5000, encoding="UTF-8", delay=0, backupCount=5)
|
||||
file_logger.setLevel(self.log_level)
|
||||
|
||||
@@ -5,8 +5,8 @@ import yaml
|
||||
|
||||
|
||||
class Settings:
|
||||
def __init__(self, **default_settings):
|
||||
self._DATA_PATH = 'data/bot/'
|
||||
def __init__(self, datadir, **default_settings):
|
||||
self._DATA_PATH = f"{datadir}/bot/"
|
||||
self._SETTINGS_PATH = self._DATA_PATH + 'settings.yaml'
|
||||
|
||||
self.default_prefix = default_settings["prefix"]
|
||||
|
||||
Reference in new issue
Block a user