Skip to content

Commit

Permalink
Merge pull request #14 from jaimegarjr/add-pr-checks
Browse files Browse the repository at this point in the history
Add pr checks pipeline
  • Loading branch information
jaimegarjr authored Feb 2, 2025
2 parents 1f90b84 + cf4a3db commit 8d1ae2c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
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

0 comments on commit 8d1ae2c

Please sign in to comment.