Git Product home page Git Product logo

amarbot's Introduction

AmarBot

A custom, non-serious, utility, and music featuring Discord bot I use for my Discord server. It features whatever fun commands I wanted to add or stuff that was requested by the community. I have a small community, so I felt comfortable enough not adding any priveledge checks yet. If you plan on using this in your own server, please keep that in mind. Also, this bot is only hosted for my community's own personal use; if you want to use this bot, you'll have to host it yourself.

Features

Music Player Commands

  • play {query} --> Plays from a query or url (almost anything youtube_dl supports).
  • queue --> Shows the current queue.
  • queue {query} --> Add a song to the queue.
  • pop --> Remove the most recent added song from the queue.
  • pop {index} --> Remove a song from the queue at index.
  • skip --> Skip the current playing song.
  • stop --> Stops the music player and disconnects the bot from the voice channel.
  • pause --> Pause the music player.
  • resume --> Resume the music player.
  • volume {1-100} --> Changes the music player's volume.

Utility Commands

  • /utils count --> Returns total number of text messages from author in a channel.
  • /utils channel_count --> Returns total number of text messages in a channel.
  • /utils guild_export --> Returns all the messages from all the channels in a Discord guild, as a JSON file in your DMs. For owners only.

Fun / Meme Commands

For obvious reasons, these commands are likely to be removed or disabled in a future release. Funny at first, but they get annoying after a while.

  • /memes roulette --> Plays a gunshot sounds and kicks a random user from the voice channel.
  • /memes driveby --> Plays machine gun sound while kicking multiple people from the voice channel.
  • /memes grenade --> Plays grenade sound while everyone connected to the current voice channel is scattered across various channels.
  • /memes minecraft --> Plays the "Mining - Minecraft Parody of Drowning" music video.
  • /memes smd --> Plays the grapefruit technique video. I'm sorry.
  • /memes goggins --> Drops a motivational quote from David Goggins.

Reminder Commands

Requires a Firebase environment to work since this uses Firestore under the hood.

  • /reminders add {who} {content} {when} --> Remind you or another user some time later in the future.
  • /reminders list --> Shows you a list with links to your upcoming reminders.
  • /reminders delete {reminder_index} --> Delete an upcoming reminder by the index. Use /reminders list command first to get the reminder_index.

Daily Inspirational Quotes

A scheduled cron job that posts inspirational quotes to a #quote-of-the-day channel if it exists. Possible by the theysaidso API.

Development Quickstart

If you want to test out this bot in your own Discord server, here's how:

  1. Start by creating an account & application on the Discord developer portal.
  2. In the "Bot" section, give access to all "Gateway Intents" and create a token. Copy the token and keep it somewhere safe for now.
  3. Invite the bot to your Discord server. Do this by going to the "OAuth2" section, then under "URL Generator", check the "bot" scope checkbox and "Administrator" permission checkbox. The generated URL at the bottom of the page should take you through the steps to invite the bot to your Discord server.
  4. Clone the repository locally.
git clone https://github.com/amaroklopcic/amarbot
  1. Create a Python virtual environment and install the required dependencies.
python -m venv .venv;
source .venv/bin/activate;
pip install -U pip setuptools wheel;
pip install -r requirements.txt;
  1. Create an .env file in the root of the project and add the following line to it, replacing the fake key below with the one you copied from the Discord developer portal.
AMARBOT_TOKEN=sbhidihBISDIbihdsbihibsidSI29H9SXx.SDU99SDISD
  1. Run it.
python amarbot.py

amarbot's People

Contributors

amaroklopcic avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

amarbot's Issues

RemindersCog TypeError: can't subtract offset-naive and offset-aware datetimes

Task exception was never retrieved
future: <Task finished name='Task-9' coro=<RemindersCog.run_reminder() done, defined at /home/amar/Documents/dev/amarbot/lib/cogs/reminders.py:84> exception=TypeError("can't subtract offset-naive and offset-aware datetimes") created at /home/amar/Documents/dev/amarbot/lib/cogs/reminders.py:50>
source_traceback: Object created at (most recent call last):
  File "/home/amar/Documents/dev/amarbot/amarbot.py", line 120, in <module>
    asyncio.run(
  File "/home/amar/.pyenv/versions/3.10.4/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/amar/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/home/amar/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/home/amar/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py", line 1888, in _run_once
    handle._run()
  File "/home/amar/.pyenv/versions/3.10.4/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/amar/Documents/dev/amarbot/lib/cogs/reminders.py", line 82, in sync_reminders
    self.schedule_reminder(reminder)
  File "/home/amar/Documents/dev/amarbot/lib/cogs/reminders.py", line 50, in schedule_reminder
    task = self.loop.create_task(self.run_reminder(reminder))
Traceback (most recent call last):
  File "/home/amar/Documents/dev/amarbot/lib/cogs/reminders.py", line 85, in run_reminder
    sleep_time = (reminder.dt - datetime.utcnow()).total_seconds()
TypeError: can't subtract offset-naive and offset-aware datetimes

Add logging

Hard to see what's going on in production without proper logging in place

Guild message exports not working in production

Was able to get a traceback for this:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 827, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
  File "/app/lib/cogs/utils.py", line 74, in export_guild
    file = open(
FileNotFoundError: [Errno 2] No such file or directory: 'exports/First Committee-export.json'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'export_guild' raised an exception: FileNotFoundError: [Errno 2] No such file or directory: 'exports/First Committee-export.json'

It looks like it just failed to open the file. My guess is the option I used for opening the file - w, maybe I should have used x instead

Music player prematurely ending streams from corrupted packets

Oddly, I only seem to get this issue when running locally after about 2 minutes of a song playing but I have never seen this happen when running in production even with 10+ hour streams. Here is the error I get:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5592de022280] Packet corrupt (stream = 0, dts = 7451648).
https://rr1---sn-vgqsrnsr.googlevideo.com/videoplayback?expire=1686735078&ei=hjSJZOrcL-fHjATthbWgCA&ip=12.345.678.910&id=o-AClI15fvGWqShJYSGZ-b3Q7pADXiGHrIj9d50yw3czFi&itag=140&source=youtube&requiressl=yes&mh=py&mm=31%2C29&mn=sn-vgqsrnsr%2Csn-vgqsknek&ms=au%2Crdu&mv=m&mvi=1&pl=15&initcwndbps=1593750&spc=qEK7BzJL9mjqFSNT5XGVEjQmFNRWXmV-Cswujtm5fA&vprv=1&svpuc=1&mime=audio%2Fmp4&ns=La-GgmNqAEGFYWUABDh-K2YN&gir=yes&clen=3387655&dur=209.281&lmt=1672525683896634&mt=1686713136&fvip=1&keepalive=yes&fexp=24007246%2C24362685%2C51000023&c=WEB&txp=5532434&n=xeVOTRh4QyAh2w&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgXrjkVihFGediyKE_6n3rXUOn9f2rJD_HxgyyM698XUsCIQDpz4bjgPuLw77rPvQRY4a9Q2j62Hv09YJAElIr3q7cWg%3D%3D&sig=AOq0QJ8wRQIgVP50JJhribjh-RUwi_2PiJp5ieggrDlie15c413rJcECIQCvJHWXx-ugKunvipqPTPxkwH8vqsoRsIiTQOANB0UmXg%3D%3D: corrupt input packet in stream 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5592de022280] stream 0, offset 0x29c10a: partial file
Error demuxing input file 0: Connection reset by peer
[aac @ 0x5592de230840] decode_band_types: Input buffer exhausted before END element found
Error while decoding stream #0:0: Invalid data found when processing input
https://rr1---sn-vgqsrnsr.googlevideo.com/videoplayback?expire=1686735078&ei=hjSJZOrcL-fHjATthbWgCA&ip=12.345.678.910&id=o-AClI15fvGWqShJYSGZ-b3Q7pADXiGHrIj9d50yw3czFi&itag=140&source=youtube&requiressl=yes&mh=py&mm=31%2C29&mn=sn-vgqsrnsr%2Csn-vgqsknek&ms=au%2Crdu&mv=m&mvi=1&pl=15&initcwndbps=1593750&spc=qEK7BzJL9mjqFSNT5XGVEjQmFNRWXmV-Cswujtm5fA&vprv=1&svpuc=1&mime=audio%2Fmp4&ns=La-GgmNqAEGFYWUABDh-K2YN&gir=yes&clen=3387655&dur=209.281&lmt=1672525683896634&mt=1686713136&fvip=1&keepalive=yes&fexp=24007246%2C24362685%2C51000023&c=WEB&txp=5532434&n=xeVOTRh4QyAh2w&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgXrjkVihFGediyKE_6n3rXUOn9f2rJD_HxgyyM698XUsCIQDpz4bjgPuLw77rPvQRY4a9Q2j62Hv09YJAElIr3q7cWg%3D%3D&sig=AOq0QJ8wRQIgVP50JJhribjh-RUwi_2PiJp5ieggrDlie15c413rJcECIQCvJHWXx-ugKunvipqPTPxkwH8vqsoRsIiTQOANB0UmXg%3D%3D: Connection reset by peer

Improve CI/CD

The current CI/CD won't reflect any package changes on deployments

Improve emoji responses

3 things:

  1. The acknowledge emoji response (:hourglass_flowing_sand:) gets remove before the finished response emoji (:ballot_box_with_check:) is added, which results in the chat "skipping up and down quickly" which looks buggy. Fix by adding the finish emoji first, then remove the acknowledge hour glass emoji.
  2. The error command emoji response currently doesn't actually report errors, only caught errors. Fix this by checking if the command returned and doesn't have the finish emoji response. Also, for errors, switch to โš ๏ธ emoji.
  3. Any commands that are refused by the bot are currently "error responses", switch these out for a new "rejected" response type and use the ๐Ÿšซ emoji.

Refactor `join_authors_vc` method

Currently, if the bot is connected to a voice channel and the play command is issued, the method calls ctx.voice_client.stop, which doesn't actually related to joining the voice channel. I added an issue for this since music functionality actually sort of depends on this behavior, so that needs to be refactored too.

Add permissions checks

Currently no permissions done on any of the commands. There isn't any commands that can be super destructive though (like role manipulation, etc.), so I think this is fine for now.

Music functionality broken

Music functionality not working in the production AmarBot. Found this in the logs:

0|amarbot  |     self._process = self._spawn_process(args, **kwargs)
0|amarbot  |   File "/root/amarbot/.venv/lib/python3.10/site-packages/discord/player.py", line 183, in _spawn_process
0|amarbot  |     raise ClientException(executable + ' was not found.') from None
0|amarbot  | discord.errors.ClientException: ffmpeg was not found.
0|amarbot  |
0|amarbot  | The above exception was the direct cause of the following exception:
0|amarbot  |
0|amarbot  | Traceback (most recent call last):
0|amarbot  |   File "/root/amarbot/.venv/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
0|amarbot  |     await ctx.command.invoke(ctx)
0|amarbot  |   File "/root/amarbot/.venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1023, in invoke
0|amarbot  |     await injected(*ctx.args, **ctx.kwargs)  # type: ignore
0|amarbot  |   File "/root/amarbot/.venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 238, in wrapped
0|amarbot  |     raise CommandInvokeError(exc) from exc
0|amarbot  | discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: ffmpeg was not found.

Looks like I forgot to install ffmpeg ๐Ÿ‘Ž I got a bit preoccupied with CI/CD today, so I'll see if I can address this tomorrow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.