Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pr checks pipeline #14

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: CI/CD Pipeline
name: Main Deploy Pipeline

on:
push:
branches:
- main

jobs:
deploy:
main-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR Checks

on:
pull_request:
branches:
- main

jobs:
pr-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Set up Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "export PATH=\$HOME/.local/bin:\$PATH" >> $GITHUB_ENV

- name: Install dependencies
run: poetry install

- name: Run Tests
run: poetry run pytest tests/unit/

- name: Lint Code
run: |
poetry run flake8 --version
poetry run flake8 .

9 changes: 4 additions & 5 deletions meowbot/application/models/music_queue.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
from collections import deque

class MusicQueue():

class MusicQueue:
def __init__(self):
self.queue = deque()
self.current_song = None

def add_to_queue(self, song):
self.queue.append(song)
return len(self.queue)

def remove_from_queue(self):
if self.queue:
return self.queue.popleft()

self.current_song = None
return None

def is_empty(self):
return len(self.queue) == 0

def clear(self):
self.queue.clear()
self.current_song = None


5 changes: 2 additions & 3 deletions meowbot/application/services/command_handler_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from discord.ext import commands
from meowbot.utils import logging, setup_logger


class CommandHandlerService:
def __init__(self):
self.logger = setup_logger(name="service.command.handler", level=logging.INFO)
self.commands_tally = {}

# TODO: can be improved by metric firing on command usage
def serve_on_command_event(self, ctx):
if ctx.command is not None:
Expand All @@ -14,4 +14,3 @@ def serve_on_command_event(self, ctx):
else:
self.commands_tally[ctx.command.name] = 1
self.logger.info(f"{ctx.command.name} was served.")

17 changes: 7 additions & 10 deletions meowbot/bot/cogs/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def play(self, ctx, *, url):
except Exception as e:
self.logger.error(f"Error when trying to play {url}: {e}")
return

position = self.music_queue.add_to_queue(player)
if position == 1 and not ctx.voice_client.is_playing():
self.start_playback(ctx.voice_client, player)
Expand All @@ -117,7 +117,7 @@ def start_playback(self, voice_client, player):
if not player or not isinstance(player, discord.AudioSource):
self.logger.error("Invalid audio source.")
return

self.logger.info(f"Type of player: {type(player)}")

def after_playback(error):
Expand All @@ -128,14 +128,11 @@ def after_playback(error):
else:
self.logger.info(f"Finished playing: {player.title}")
self.play_next(voice_client)

voice_client.play(
player,
after=after_playback
)

voice_client.play(player, after=after_playback)
voice_client.source.volume = 0.10
self.logger.info(f"Now playing: {player.title}")

def play_next(self, voice_client):
if not self.music_queue.is_empty():
next_song = self.music_queue.remove_from_queue()
Expand Down Expand Up @@ -167,13 +164,13 @@ async def queue(self, ctx):
embed.add_field(name=f"Song {i+1}", value=song.title, inline=False)
await ctx.send(embed=embed)
self.logger.info("Queue displayed.")

@commands.hybrid_command(name="clear", description="Clears the current queue")
async def clear(self, ctx):
self.music_queue.clear()
await ctx.send("Queue has been cleared!")
self.logger.info("Queue has been cleared.")

@commands.hybrid_command(name="skip", description="Skips the current song")
async def skip(self, ctx):
if ctx.voice_client.is_playing():
Expand Down