Skip to content

Commit

Permalink
Merge pull request #85 from r-Norge/dev
Browse files Browse the repository at this point in the history
Update master to use the latest versions of dependencies.
  • Loading branch information
Ev-1 authored Mar 28, 2024
2 parents 6a36d03 + 687f76d commit 8b69816
Show file tree
Hide file tree
Showing 39 changed files with 466 additions and 366 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,9 @@ on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
env:
CheckFiles: "bot.py musicbot/"
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/[email protected]
with:
python-version: 3.10.7

- name: Lint with flake8
run: |
pip install flake8
flake8 ${CheckFiles}
- name: Check with Isort
run: |
pip install isort
isort --check --sp setup.cfg ${CheckFiles}
- uses: chartboost/ruff-action@v1

test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.7-alpine
FROM python:3.11.8-alpine

LABEL maintainer="Roxedus"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ networks:
services:
lavalink:
hostname: lavalink
image: fredboat/lavalink:dev
image: ghcr.io/lavalink-devs/lavalink:4
networks:
- internal
volumes:
Expand Down
30 changes: 15 additions & 15 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Discord Packages
import discord
import lavalink
from discord.ext import commands
from discord.flags import MemberCacheFlags

import codecs
import os
import time
import traceback
from argparse import ArgumentParser, RawTextHelpFormatter
from typing import Optional

import discord
import lavalink
from discord.ext import commands
from discord.flags import MemberCacheFlags

import aiohttp
import yaml

# Bot Utilities
from musicbot.utils.localisation import Aliaser, LocalizedContext, Localizer, LocalizerWrapper
from musicbot.utils.logger import BotLogger
from musicbot.utils.settingsmanager import Settings
Expand Down Expand Up @@ -49,12 +47,12 @@ def __init__(self, datadir, debug: bool = False):
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'))
self.aliaser = Aliaser(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
self.localizer: Localizer = Localizer(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
self.aliaser: Aliaser = Aliaser(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))

self.datadir = datadir
self.debug = debug
self.main_logger = logger
self.debug: bool = debug
self.main_logger: BotLogger = logger
self.logger = self.main_logger.bot_logger.getChild("Bot")
self.logger.debug("Debug: %s" % debug)
self.lavalink: Optional[lavalink.Client] = None
Expand All @@ -68,7 +66,7 @@ async def process_commands(self, message):
ctx = await self.get_context(message, cls=LocalizedContext)

# Replace aliases with commands
ctx = self.aliaser.get_command(ctx)
ctx: LocalizedContext = self.aliaser.get_command(ctx)

# Add the localizer
if ctx.command and ctx.command.cog_name:
Expand Down Expand Up @@ -99,9 +97,11 @@ async def on_ready(self):
self.logger.debug("Bot Ready")

self.session = aiohttp.ClientSession(loop=self.loop)
await self.change_presence(activity=discord.Game(type=0,
name=conf["bot"]["playing status"]),
status=discord.Status.online)

if presence := conf["bot"]["playing status"]:
await self.change_presence(activity=discord.Game(type=0,
name=presence),
status=discord.Status.online)

def run(self):
try:
Expand Down
22 changes: 6 additions & 16 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ default:
# Make a new virtual environment
[private]
make_venv:
python3.10 -m venv {{env_name}}
python3 -m venv {{env_name}}
{{python}} -m pip install --upgrade pip
{{python}} -m pip install -r requirements.txt
{{python}} -m pip install flake8
{{python}} -m pip install isort
{{python}} -m pip install pytest

# Make the environment if it does not exit
[private]
Expand All @@ -24,23 +21,16 @@ run: venv
{{python}} bot.py

# Run with debug logging enabled
debug: run
--debug
debug: venv
{{python}} bot.py --debug

clean:
rm -rf {{env_name}}
# Lint with flake8
flake: venv
{{python}} -m flake8 bot.py musicbot

# Fix import order with isort
isort: venv
{{python}} -m isort --sp setup.cfg bot.py musicbot

# Run both isort and flake8
lint: venv
just isort
just flake
# Run ruff
lint: venv
{{python}} -m ruff check . --fix

# Run tests
test: venv
Expand Down
11 changes: 5 additions & 6 deletions musicbot/cogs/cogmanager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Discord Packages
from discord.ext import commands

import traceback

from discord.ext import commands

from bot import MusicBot
from musicbot.utils.userinteraction import ClearMode, Scroller

from ..utils.userinteraction import ClearOn, Scroller
from .helpformatter import commandhelper


Expand All @@ -21,7 +20,7 @@ async def _cogmanager(self, ctx):
ctx.localizer.prefix = 'help' # Ensure the bot looks for locales in the context of help, not cogmanager.
paginator = commandhelper(ctx, ctx.command, ctx.invoker, include_subcmd=True)
scroller = Scroller(ctx, paginator)
await scroller.start_scrolling(ClearOn.AnyExit)
await scroller.start_scrolling(ClearMode.AnyExit)

@_cogmanager.command()
@commands.is_owner()
Expand Down Expand Up @@ -59,7 +58,7 @@ async def _reload(self, ctx, *, module):
@_cogmanager.command(name='reloadall')
@commands.is_owner()
async def _relaod_all(self, ctx):
"""Reloads all extensions"""
"""Reloads all extensions."""
try:
for extension in self.bot.extensions:
if extension == 'musicbot.cogs.cogmanager':
Expand Down
9 changes: 4 additions & 5 deletions musicbot/cogs/errors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Discord Packages
import sys

import discord
from discord.ext import commands

import sys

from bot import MusicBot
from musicbot.utils.userinteraction import ClearMode, Scroller

from ..utils.userinteraction import ClearOn, Scroller
from .helpformatter import commandhelper
from .music import music_errors

Expand All @@ -31,7 +30,7 @@ async def on_command_error(self, ctx, err):
isinstance(err, commands.BadArgument)):
paginator = commandhelper(ctx, ctx.command, ctx.invoker, include_subcmd=False)
scroller = Scroller(ctx, paginator)
await scroller.start_scrolling(ClearOn.AnyExit)
await scroller.start_scrolling(ClearMode.AnyExit)

if isinstance(err, (commands.CommandNotFound)):
return
Expand Down
8 changes: 4 additions & 4 deletions musicbot/cogs/helpformatter/help.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Discord Packages
from discord.ext import commands

from bot import MusicBot
from musicbot.utils.userinteraction.scroller import ClearMode, Scroller

from ...utils.userinteraction.scroller import ClearOn, Scroller
from .helpformatter import coghelper, commandhelper, helper, prefix_cleaner


class Help(commands.Cog):
"""Help command"""
"""Help command."""

def __init__(self, bot: MusicBot):
self.bot: MusicBot = bot

Expand All @@ -35,4 +35,4 @@ async def help(self, ctx): # Takes no args because reasons(using the view direc
paginator = await coghelper(ctx, thing)

scroller = Scroller(ctx, paginator)
await scroller.start_scrolling(ClearOn.Timeout | ClearOn.ManualExit)
await scroller.start_scrolling(ClearMode.Timeout | ClearMode.ManualExit)
11 changes: 5 additions & 6 deletions musicbot/cogs/helpformatter/helpformatter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Discord Packages
from discord.ext import commands

import re

from ...utils.userinteraction import HelpPaginator
from discord.ext import commands

from musicbot.utils.userinteraction import HelpPaginator

usermention = r"<@!?\d{17,19}>"

Expand Down Expand Up @@ -91,14 +90,14 @@ def commandhelper(ctx, command, invoker, include_subcmd=True):
description = f"```{description}```"
paginator = HelpPaginator(max_size=5000, max_fields=5, color=ctx.me.color, title=cmd, description=description)

for sub_command, sub_cmd_dict in sub_commands.items():
for _sub_command, sub_cmd_dict in sub_commands.items():
paginator.add_command_field(sub_cmd_dict)
paginator.add_page_indicator(ctx.localizer, "{pageindicator}", _prefix=ctx.prefix)
return paginator


def prefix_cleaner(ctx):
""" Changes mentions to prefixes when commands are invoked with mentions."""
"""Changes mentions to prefixes when commands are invoked with mentions."""
bot = ctx.bot
prefix = ctx.prefix
if re.match(usermention, prefix):
Expand Down
18 changes: 6 additions & 12 deletions musicbot/cogs/misc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Discord Packages
import platform
import time

import discord
from discord.ext import commands
from lavalink import __version__ as LavalinkVersion

import platform
import time

from bot import MusicBot

from ..utils import bot_version
from musicbot.utils import bot_version


class Misc(commands.Cog):
Expand Down Expand Up @@ -48,9 +46,7 @@ async def _guilds(self, ctx):

@commands.command()
async def musicinfo(self, ctx):
"""
Info about the music player
"""
"""Info about the music player."""
embed = discord.Embed(title='{music.title}', color=ctx.me.color)

listeners = 0
Expand Down Expand Up @@ -79,9 +75,7 @@ async def reload_alias(self, ctx):

@commands.command()
async def info(self, ctx):
"""
Info about the bot
"""
"""Info about the bot."""
guilds = len(self.bot.guilds)
members = len(self.bot.users)

Expand Down
Loading

0 comments on commit 8b69816

Please sign in to comment.