From bd1af47c0c1fc34e57c9864afb3642bac3fe73b3 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 27 Aug 2020 19:37:19 +0200 Subject: [PATCH 1/5] Test linter --- .github/workflows/build.yml | 47 +++++++++++++++++++++++++++++ .github/workflows/build.yml-wait | 52 -------------------------------- 2 files changed, 47 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/build.yml-wait diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7a46fb5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +name: Test And Build BOT +on: [push, pull_request] + +jobs: + flake8: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Lint Code Base + uses: github/super-linter@v3 + env: + VALIDATE_ALL_CODEBASE: true + VALIDATE_PYTHON_BLACK: false + DEFAULT_BRANCH: master + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # build-and-push: + # needs: flake8 + # runs-on: ubuntu-latest + # env: + # repo: rnorge/music + # ref: ${{github.ref}} + # DOCKER_USERNAME: roxedus + # DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + # steps: + # - uses: actions/checkout@v2 + # - name: Build the Docker image + # run: | + # branch="${ref##*/}" + # docker build -t $repo:$branch -t $repo:$branch-${{github.sha}} . + # - name: Master tag + # if: github.ref == 'refs/heads/master' + # run: | + # branch="${ref##*/}" + # bot_ver=$(grep -i bot_version cogs/utils/bot_version.py | cut -d" " -f3 | tr -d \") + # docker tag $repo:$branch $repo:$bot_ver + # - name: Bump version and push tag + # if: github.ref == 'refs/heads/master' + # uses: mathieudutour/github-tag-action@v3 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # - name: Login to registry + # if: github.event.pull_request == false + # run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin + # - name: Pushes the Docker image + # if: github.event.pull_request == false + # run: docker push $repo diff --git a/.github/workflows/build.yml-wait b/.github/workflows/build.yml-wait deleted file mode 100644 index a49fd18..0000000 --- a/.github/workflows/build.yml-wait +++ /dev/null @@ -1,52 +0,0 @@ -name: Test And Build BOT -on: [push, pull_request] - -jobs: - flake8: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.8 - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - name: Lint with flake8 - run: | - pip install flake8 - flake8 --max-line-length 120 --statistics ${FLAKE_FILES} - - build-and-push: - needs: flake8 - runs-on: ubuntu-latest - env: - repo: rnorge/music - ref: ${{github.ref}} - DOCKER_USERNAME: roxedus - DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} - steps: - - uses: actions/checkout@v1 - - name: Build the Docker image - run: | - branch="${ref##*/}" - docker build -t $repo:$branch -t $repo:$branch-${{github.sha}} . - - - name: Master tag - if: github.ref == 'refs/heads/master' - run: | - branch="${ref##*/}" - bot_ver=$(grep -i bot_version cogs/utils/bot_version.py | cut -d" " -f3 | tr -d \") - docker tag $repo:$branch $repo:$bot_ver - - - name: Bump version and push tag - if: github.ref == 'refs/heads/master' - uses: mathieudutour/github-tag-action@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Login to registry - if: github.event.pull_request == false - run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin - - - name: Pushes the Docker image - if: github.event.pull_request == false - run: docker push $repo From 17eed890baab6d59937fb98fbcbe12a237bc9b8a Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 27 Aug 2020 20:32:02 +0200 Subject: [PATCH 2/5] More rules! --- setup.cfg | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index fce66fb..92598fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,7 @@ -[pycodestyle] -max_line_length = 120 +[flake8] +max-line-length = 120 +count = True +statistics = True [isort] known_discord = discord,lavalink @@ -11,4 +13,14 @@ no_lines_before = LOCALFOLDER indent = " " line_length = 120 balanced_wrapping = True -multi_line_output = 4 \ No newline at end of file +multi_line_output = 4 + +[pycodestyle] +max_line_length = 120 + +[pylint.FORMAT] +max-line-length=120 + +[pylint.BASIC] +variable-naming-style=camelCase +constant-naming-style=camelCase From e5684d3789397b950e81fe4f8d9cc70578f47965 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 27 Aug 2020 20:32:27 +0200 Subject: [PATCH 3/5] I Love VSCode --- .vscode/extensions.json | 7 +++++++ .vscode/launch.json | 15 +++++++++++++++ .vscode/settings.json | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..aacd762 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "oderwat.indent-rainbow", + "ms-python.python", + "ms-python.vscode-pylance" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..958f4d6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [{ + "name": "Debug Bot", + "type": "python", + "request": "launch", + "program": "bot.py", + "console": "integratedTerminal", + "args": ["-D", "-d", "data"], + "host": "localhost" + }] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3f76c37 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "python.languageSever": "Pylance", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.linting.flake8Enabled": true, + "python.linting.pycodestyleEnabled": true, + "[python]": { + "editor.rulers": [120], + }, + "[Dockerfile]": { + "editor.formatOnSave": false + }, + "editor.tabSize": 4 + +} \ No newline at end of file From d33bf1f72319cd02d77cd8472c23d97a536127c8 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 27 Aug 2020 20:33:27 +0200 Subject: [PATCH 4/5] Fix linter errors --- README.md | 20 +++++++++++--------- cogs/errors.py | 7 +++---- cogs/music.py | 1 - cogs/nodemanager.py | 6 ++++-- cogs/utils/alias.py | 1 - 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a7a965f..09f97ec 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # WIP - Shite Music Bot [![Build Status](https://jenkins.roxedus.net/buildStatus/icon?job=MusicBot%2Fdev)](https://jenkins.roxedus.net/job/MusicBot/job/dev/) -[![](https://images.microbadger.com/badges/image/rnorge/music:dev-amd64.svg)](https://microbadger.com/images/rnorge/music:dev-amd64 "Get your own image badge on microbadger.com") +[![MicroBadger](https://images.microbadger.com/badges/image/rnorge/music:dev-amd64.svg)](https://microbadger.com/images/rnorge/music:dev-amd64 "Get your own image badge on microbadger.com") + +## Features -### Features: - Translations, get the bot in your preferred langauge! - Round Robin style queue, you won't have to wait forever for your songs to play. - Noice per server customization options. @@ -12,18 +13,19 @@ - Lyrics command that sometimes gives the correct lyrics - DJ roles +### Setup -#### Setup 1. Change or copy data/config.yaml.example to config.yaml 2. Create or find a [lavalink](https://github.com/Frederikam/Lavalink) server you can use. 3. Add your bot token and lavalink server. 4. Edit any other settings you want. -5. install requirements -> python -m pip install -r requirements.txt +5. install requirements `python -m pip install -r requirements.txt` 6. run the bot :) -#### Docker -#### Compose Example: +### Docker + +### Compose Example + ````yaml version: '3' networks: @@ -42,7 +44,7 @@ services: - lavalink volumes: - /compose/BottStack/lavalink/application.yml:/opt/Lavalink/application.yml - bot: + bot: container_name: ProdMaster image: rnorge/music networks: @@ -51,4 +53,4 @@ services: volumes: - /compose/BottStack/ProdBetaMaster/script:/diks - /compose/BottStack/ProdBetaMaster/data:/app/data -```` \ No newline at end of file +```` diff --git a/cogs/errors.py b/cogs/errors.py index f0ea6da..92117d7 100644 --- a/cogs/errors.py +++ b/cogs/errors.py @@ -57,10 +57,9 @@ class Errors(commands.Cog): elif (err.original == 'You need to be in my voicechannel.'): return await send_error_embed('{errors.my_channel}') - if isinstance(err, commands.CommandOnCooldown): await ctx.send(f"{ctx.message.author.mention} Command is on cooldown. " - f"Try again in `{err.retry_after:.1f}` seconds.") + f"Try again in `{err.retry_after:.1f}` seconds.") elif isinstance(err, commands.NoPrivateMessage): await ctx.send('That command is not available in DMs') @@ -70,11 +69,11 @@ class Errors(commands.Cog): if self.bot.debug: tb = err.__traceback__ traceback.print_tb(tb) - self.logger.debug("Error running command: %s\nTraceback: %s" % (ctx.command, err)) + self.logger.debug("Error running command: %s\nTraceback: %s" % (ctx.command, err)) else: to_log = (RuntimeError, commands.CheckFailure, commands.CommandInvokeError, - commands.NoPrivateMessage) + commands.NoPrivateMessage) if isinstance(err, to_log): self.logger.debug("Error running command: %s\nTraceback: %s" % (ctx.command, err)) diff --git a/cogs/music.py b/cogs/music.py index 3742dce..9720aad 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -16,7 +16,6 @@ from typing import Optional from bs4 import BeautifulSoup from .utils import checks, thumbnailer, timeformatter -from .utils.mixplayer import MixPlayer from .utils.paginator import QueuePaginator, Scroller, TextPaginator from .utils.selector import Selector diff --git a/cogs/nodemanager.py b/cogs/nodemanager.py index 81f8530..ef08c9b 100644 --- a/cogs/nodemanager.py +++ b/cogs/nodemanager.py @@ -8,9 +8,11 @@ import codecs import yaml -from .utils.mixplayer import MixPlayer +# Bot Utilities from cogs.helpformatter import commandhelper from cogs.utils.paginator import Scroller +from .utils.mixplayer import MixPlayer + class NodeManager(commands.Cog): def __init__(self, bot): @@ -51,7 +53,7 @@ class NodeManager(commands.Cog): if node['name'] in name_cache: continue - self.bot.lavalink.add_node(**node) + self.bot.lavalink.add_node(**node) self.logger.debug("Adding Lavalink node: %s on %s with the port %s in %s" % ( node['name'], node['host'], node['port'], node['region'],)) diff --git a/cogs/utils/alias.py b/cogs/utils/alias.py index d7a0f2a..8a68d61 100644 --- a/cogs/utils/alias.py +++ b/cogs/utils/alias.py @@ -6,7 +6,6 @@ from os import path import yaml - """ Not the prettiest this, works by replacing any found aliases in a command string with the actual command names. Allows per guild aliases of subcommands without doing anything to discord.py itself. Suggestions of better/correct From 93224cdc279e929f8f1024a0c98eacd22ed24820 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 27 Aug 2020 20:33:51 +0200 Subject: [PATCH 5/5] Test Workflow --- .github/workflows/build.yml | 102 ++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a46fb5..d92a696 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,44 +4,70 @@ on: [push, pull_request] jobs: flake8: runs-on: ubuntu-latest + env: + CheckFiles: "bot.py cogs/" steps: - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Lint with flake8 + run: | + pip install flake8 + flake8 ${CheckFiles} - - name: Lint Code Base - uses: github/super-linter@v3 - env: - VALIDATE_ALL_CODEBASE: true - VALIDATE_PYTHON_BLACK: false - DEFAULT_BRANCH: master - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # build-and-push: - # needs: flake8 - # runs-on: ubuntu-latest - # env: - # repo: rnorge/music - # ref: ${{github.ref}} - # DOCKER_USERNAME: roxedus - # DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} - # steps: - # - uses: actions/checkout@v2 - # - name: Build the Docker image - # run: | - # branch="${ref##*/}" - # docker build -t $repo:$branch -t $repo:$branch-${{github.sha}} . - # - name: Master tag - # if: github.ref == 'refs/heads/master' - # run: | - # branch="${ref##*/}" - # bot_ver=$(grep -i bot_version cogs/utils/bot_version.py | cut -d" " -f3 | tr -d \") - # docker tag $repo:$branch $repo:$bot_ver - # - name: Bump version and push tag - # if: github.ref == 'refs/heads/master' - # uses: mathieudutour/github-tag-action@v3 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # - name: Login to registry - # if: github.event.pull_request == false - # run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin - # - name: Pushes the Docker image - # if: github.event.pull_request == false - # run: docker push $repo + - name: Check with Isort + run: | + pip install isort + isort --check --sp setup.cfg ${CheckFiles} + - name: Sort with Isort + if: failure() + run: | + isort --sp setup.cfg ${CheckFiles} + - name: Create Pull Request + if: failure() + uses: peter-evans/create-pull-request@v2 + with: + token: ${{ secrets.GH_TOKEN }} + branch: actions/auto + commit-message: Changes done by tests + committer: Roxedus + title: Linter changed files + + build-and-push: + needs: flake8 + runs-on: ubuntu-latest + env: + repo: rnorge/music + ref: ${{github.ref}} + DOCKER_USERNAME: roxedus + DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + + steps: + - uses: actions/checkout@v2 + - name: Build the Docker image + run: | + branch="${ref##*/}" + docker build -t $repo:$branch -t $repo:$branch-${{github.sha}} . + + - name: Master tag + if: github.ref == 'refs/heads/master' + run: | + branch="${ref##*/}" + bot_ver=$(grep -i bot_version cogs/utils/bot_version.py | cut -d" " -f3 | tr -d \") + docker tag $repo:$branch $repo:$bot_ver + + - name: Bump version and push tag + if: github.ref == 'refs/heads/master' + uses: mathieudutour/github-tag-action@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to registry + if: github.event.pull_request == false + run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin + + - name: Pushes the Docker image + if: github.event.pull_request == false + run: docker push $repo