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

[CogV2] Bot rewrite and various useful commands #1973

Merged
merged 529 commits into from
Mar 14, 2020

Conversation

TheerapakG
Copy link
Member

@TheerapakG TheerapakG commented Oct 24, 2019

After creating your pull request, tick these boxes if they are applicable to you.

  • My changes do not conflict with the review branch (the latest developmental version)
  • My changes can be run on Python 3.5.3 or higher (including Python 3.8)
  • I have tested my changes (checkboxes that are checked in front of commands and configs below is minimally tested)

This PR does not target review branch as this is a breaking change and rhino suggested this https://discordapp.com/channels/129489631539494912/157598062020132865/633230797729562634

Description

It is kinda hard to manage all those branches and solving merge conflicts when merging them together so I just combine all these things together, for easier reviewing and creating a lot less hassle when fixing something. Nearly all of the features are completed anyway so there is no point in keeping separate branches.

This PR combines: #1938, #1917, #1916, #1915, #1904

CORE

At the core, this PR changes how the bot works to

  1. Utilize discord.ext cogs, which allow us to isolate failures if it were to happen.
  2. Have the bot rely less on setting members of the data model (where sensible) and use newly provided functions to interact with it instead. This encourages code reusability and reduces potential bugs

This PR breaking change is that it changes several models related to player and playlists for ease of usage in the future; hence, data saved in the data folder will be incompatible. There are checks for the version of the data file to prevents incompatible saves but conversion script are currently NOT provided.

The player got reworked and have some states removed. Check the implementation for details.

If there is no entry in the playlist, the player would now poll the playlist at an interval for next entry rather than stopping itself.

Playlists got reworked and now do not take raw urls and make entries inside itself. It relies on entries added to it instead. It can also be named.

Playlists are now objects which are in control of caching instead and hence, can be set to cache multiple entries in the list before the player pulls it out. However, there is no option to change this from the default number (1) as of yet. Check the implementation for details.

Downloader got reworked and now uses its internal loop which it got when it is instantiated instead. Check the implementation for details.

Entries have dedicated functions to create them. Check the implementation for details.

Aliases are now being specified in .ini file so that it is uniform for all configuration files.

Due to the implementation of the cog loader (copied from my ModuBot), the run script has been modified.

UPDATING, RESTARTING AND SHUTTING DOWN

With the update command, you can now update the bot through Discord. This should reduce the pain for people who host the bot when a new update rolled out.

Restart command now reloads the bot script correctly (for the most part). Most of the updates will likely work without you needing to actually rerun the script.

Windows users can now close the bot window using the x button if they have pywin32 installed.

MULTIPLE OWNERS

You can now specify multiple users as owner to allow them to use owner-restricted commands. Just separate ids with spaces when adding them to the OwnerID config.

COGS AND MODULES (#1776 -> #1904)

Modules can be loaded dynamically. You can load modules and setting aliases for commands via commands in this category

commands in this category:

  • loadmodule - load/reload specified module
  • cogmodule - get module name containing the implementation of the cog
  • add - group command
    • alias - add an alias to the command
  • remove - group command
    • alias - remove an alias from the command

LOCAL FILE (#1938)

This PR allows users to queue local files, with the owner having the ability to specify which folder should be visible to the users, so that important video/audio files were not accidentally queueable.

configurations in this category:

[Locals]

  • AllowQueueingLocal - determines whether queueing local files would be allowed
  • LocalOnlySpecifiedDir - determine whether users need to enter a full path to the local file. This could prevent someone from accidentally queueing local files.
  • LocalDir - limits queueing local files to these directories

commands in this category:

  • lib - List all files in the local folder which could potentially be played.

PLAYLIST (#1917)

This PR allows one server to hold multiple playlists, allowing moderators to queue some stuff up for hot-swapping later when needed.

commands in this category:

  • playlist - group command
    • list - list all playlists in the server
      • other names - list playlist
    • add - add playlist with specified name
      • other names - add playlist
    • remove - remove playlist with the specified name
      • other names - remove playlist
  • add - group command
    • entries - group command
      • playlist - append the specified playlist's entries to target
      • url - generate a playlist from specified URL and named it as specified
  • list - group command
    • entries - list entries in the playlist
      • other names - queue
  • remove - group command
    • entry - remove the specified entry in the specified playlist
      • other names - re
    • entries - clear entries the specified playlist
      • other names - res, clear
  • swap - swap current server's playlist with the one specified
  • fromfile - generate a playlist from .txt file with the same format as _autoplaylist.txt and named it as specified

AUTOPLAYLIST (#1727 -> #1911 -> #1917)

I realized that having one autoplaylist is not ideal for the bot that might be hosted for multiple servers. This PR allows servers to specify some of the playlists as autoplaylists, independently for each server (This also means that some entry might be a local file or even a stream).

configurations in this category:

  • [MusicBot]
    • InstaPlayIfAuto - determine whether adding entries should skip the autoplaylist

commands in this category:

  • aprandom - changes whether autoplaylist should randomize the entry.
  • save - add the playing song to the current autoplaylist.
  • swapap - swap autoplaylist to the playlist.

commands removed:

  • resetplaylist

CAPTION (#1916)

Allows users to get the caption of the queued track (if the service have one)

configurations in this category:

  • [Caption]
    • CaptionSplitDuration - Duration (in seconds) that the bot will consider as the beginning of a new section. Extra newline will be added between sections to improve readability.

commands in this category:

  • caption - get caption for the current song.
  • captlang - display languages that are possible to get a caption for.
  • reloadcapt - try to download caption for current entry again.

WEBAPI (#1776 -> #1904)

This cog introduces a way for the bot to communicate with other programs (even those which are hosted elsewhere) securely, allowing us to develop other programs that utilize the bot independently (such as GUI program for managing the bot). This cog was originally meant to be a demonstration of the cog loading/unloading mechanism. This cog is disabled by default.

configurations in this category:

  • [WebApi]
    • WebApiHTTPPort
    • WebApiHTTPSPort
    • SSLCertFile - path to ssl certificate file
    • SSLKeyFile - path to ssl key file
    • WebApiPersistentTokens - tokens generated (refer to commands section for how to generate it) in a session will be kept.

commands in this category:

  • gentoken - generate a token that will be needed for interacting via webapi
  • revoketoken - revoke the specified token access to the webapi

OTHER SMALL FEATURES

Related issues (if applicable)

@TheerapakG TheerapakG added the a/permissions Affects the bot's permissions system label Dec 16, 2019
@amit177 amit177 self-requested a review March 14, 2020 10:18
@TheerapakG TheerapakG merged commit dd9a9ed into Just-Some-Bots:cogs-rewrite Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/backend Affetcs the backend (youtube-dl/processing) a/cmds Affects the bot's commands system a/frontend Affects the frontend (visual appearance/ feel of the bot) a/options affects the bot's options system a/permissions Affects the bot's permissions system a/playback Affects the playback (ffmpeg/Discord) aspect of the bot t/enhancement [PRs] Someone did a thing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants