Alpha version of ALBot 2.0, the spiritual successor to ALBot

Overview

ALBot 2.0 Alpha

Alpha version of ALBot 2.0, the spiritual successor to ALBot. ALBot 2.0 uses Discord.js to interface with the Discord API, supplanting ALBot's dependency on the deprecated Discord.py library.

To get started working on the bot, first clone the repository! Then proceed to the Dependencies and Building and Testing sections of this README.

Dependencies

The only non-npm managed dependency is Node.js. Install Node.js here. This will also install npm. The necessary versions for node and npm are:

  • node: v16.13.2
  • npm: 8.1.2

After installing node and npm, run the following command:

npm install

Linting

Running this command will install the node package dependencies. One of these is ESLint, a linter for Javascript. If desired, you can install an ESLint extension for your development environment to provide code highlighting based on the project's linting rules.

Building and Testing

To run and test the bot locally, you will need to set up a a test bot and a bot testing server in Discord. Only you and the test bot need to be in this server.

Creating your test bot is a quick process, and just requires changing some settings in Discord. Follow the guide linked here to create your bot. Using its token will be discussed shortly.

Once your bot is created, create a server for bot testing under your Discord account. Then, follow this guide to add your bot to the testing server. You will need to give the bot the following permissions: bot and applications.commands.

Good work! Now your test bot application is created and waiting in your server. The last thing you need to do for setup is create a config.json file.

This file is loaded by the application at runtime and stores confidential tokens and IDs specific to your bot. NEVER COMMIT YOUR config.json! If you do, promptly go to Discord developer portal and request new tokens.

To create the config.json, first take a look at config.json.example. This file provides the basic schema for your config.json. To create your config.json, copy the contents of config.json.example into yours but substitute the following values for each of the keys in the JSON object as follows:

  • clientId: Substitute in the client id provided for your bot application found on the Discord Developer Portal. You can find it under the OAuth2 section.
  • guildId: Substituted in the guild id for your bot testing server. You can find it in Discord by right-clicking your server in Discord and then selecting the "Copy ID" option at the bottom. You will have to enable Developer Mode to see this option.
  • token: Substitute in the token for your bot application found on the Discord Developer Portal.

Once your config.json is setup, it's time to run the application!

First, run the following to deploy the commands to the bot:

npm run deploy-commands

Next, launch the bot!

npm run start

If you see a "Ready! Logged in as. . ." message, you've succeeded!

Architecture

ALBot 2.0's functionality is distributed across several files. The src/index.ts contains the 'main' of the program, and should be executed using node to launch the bot (npm run start or ts-node src/index.ts). The client object in index.ts is the bot - that is, it contains all the functionality as properties.

The commands ALBot can perform are stored in the src/commands/ directory. Each command is stored in its own .ts file with the name of the command being the file name (e.g. command /foo is in foo.ts). All commands implement the ICommand inteface defined in src/icommand.ts.

Each command object implements the ICommand inteface. ICommand describes an inteface with the following attributes:

  • name: the name of the command
  • description: a description of its purpose
  • execute(interaction: Interaction): a function which contains the commands functionality.

Dispatching interactions to the proper commands is handled by the interactionCreate event (see events/interactionCreate.js). The commands are compiled into a key-value store at runtime when the bot is started, with names as keys and the object as value (see src/commands.ts). Import commands.ts to access this store.

The bots interactivity is implemented using an event handling architecture wherein event handlers are specified by modules in the src/events/ directory. Each .ts file in events/ exports a distinct event handler. The naming scheme mimics that of the command files: an event foo is handled in foo.js.

Each event handler implements the IEvent interface type, which includes the following attributes:

  • name: name of the event being handled
  • once (optional): true if the command only executes once, false if it should be run on every ocurrence.
  • execute(any[]): void | Promise<void>: the function executed to handle the event

These events are loaded into the client object at runtime when the bot is started.

Acknowledgement

This project was built with the help of the Discord.js guides.

Comments
  • Commands for Finding Information about Projects

    Commands for Finding Information about Projects

    Create commands for finding information about active club projects, such as associated roles, GitHub repositories, related tutorials, etc.

    Feel free to recommend ideas for project-related commands in this thread!

    enhancement 
    opened by awhigham9 8
  • Awhigham9/add polling

    Awhigham9/add polling

    Add a MVP set of commands for running polls.

    Polls only support 1 question currently, though code has features for multi-question polls later. Each poll is assigned an integer id at creation. Polls are stored in-memory and erased at bot shutdown.

    Adds 5 commands:

    /startpoll

    Creates a new poll. The poll starts "open", meaning it can be voted on.

    Args:

    • pollname: name of the poll
    • question: string capturing the polls question
    • choices: string capturing the question's choices delimited by |

    /polls

    Lists polls and their IDs, both closed and open. Closed polls have an asterisk to mark them as such.

    /seepoll

    View a poll. Shows name, question, options, and current votes for each option.

    Args:

    • pollid: ID of the poll (can be found with /polls)

    /closepoll

    Close a poll to stop new votes.

    Args:

    • pollid: ID of the poll (can be found with /polls)

    /vote

    Vote on a poll.

    Args:

    • pollid: ID of the poll (can be found with /polls)
    • choices: Choices for each question of the poll, expressed as number (e.g. 1 means the first option). Support for multiple questions exists, by having numbers delimited by |. This is unused currently.
    opened by awhigham9 7
  • Commands for Assigning and Managing Roles

    Commands for Assigning and Managing Roles

    /giveRole Command

    Create a slash command that allows server members to assign themselves a role. For example, /giveRole <role_name> will give the sender the role with name <role_name>. This command should allow users to give themselves only roles from an approved list of roles, the "permit list".

    /openRole and /closeRole Commands

    Create an admin-only slash command used to add roles to the "permit list": /openRole <role_name>. When an admin runs this command, it will "permit" the role with name <role_name> and make it possible for non-admin users to give themselves this role using /giveRole.

    Create an admin-only slash command used to remove roles from the "permit list": /closeRole <role_name>. When an admin runs this command, it will "block" the role with name <role_name> and make it impossible for non-admin users to give themselves this role using /giveRole.

    It would be ideal if the "permit list" was persistent across bot startups. This could be implemented with a small SQLite database, or even a basic read/write JSON file. (Bonus Feature: It would be great if a configuration file could provided via the command line when starting the bot to pre-populate the "permit list". Otherwise, the "permit list" will start empty).

    /roles Command

    Create a command to see what roles are on the "permit list", /roles. This should return a message indicating which roles are self-assignable with /giveRole.

    User Story Example

    For example, suppose the server has roles [role1, role2, moderator] where moderator is a server-specific privileged role. The admin will not want non-admin users be able to self-assign the moderator role. Then, the admin will run /openRole role1 and openRole role2 to permit users to self-assign these roles using /giveRole role1 or /giveRole role2.

    Feel free to suggest modifications to these three role commands here, or open other issues for extensions to these commands elsewhere!

    enhancement 
    opened by awhigham9 5
  • Add Centralized Code for Logging

    Add Centralized Code for Logging

    Add utilities to the code for logging information into a log file while the bot is deployed on the server.

    The logs should offer several different levels of message severity. For example levels might include, in increasing severity:

    • Debug
    • Info
    • Warning
    • Error
    • Critical

    It would be best to accomplish this using a high-quality logging library offered through npm. A custom implementation will work if there isn't a suitable library available.

    Once the logging utility is added, the other files in the code base should begin to incorporate it for event-driven logging.

    enhancement good first issue help wanted 
    opened by awhigham9 2
  • Commands for Running Polls

    Commands for Running Polls

    Create commands for starting polls, voting in polls, stopping polls, viewing poll results, and seeing active polls

    Polls have many potential variants: anonymous/caucus, timed/untimed, single vote/multiple vote, ranked choice, etc.

    For these commands, the MVP is anonymous, single vote, multiple choice polls without automated timing. Users should be able to vote by DMing the bot a slash command to vote. This will make it anonymous.

    /startPoll Command

    Create a command which will initialize a new poll with a name, questions, and choices: /startPoll.

    The exact argument structure is up to the implementer, but it should allow multiple questions in the poll, with a minimum of 1 question. Each question should have at least one available answer. Once the command is run successfully, the bot should reply with a message showing the name of the poll and its questions in readable format. The bot should also include a unique identifier in this response message; this could be accomplished by making the name unique or create a unique ID for each poll. The poll should be marked as "active" upon creation within the bot.

    /stopPoll Command

    Create a command which will stop an existing, active poll and prevent users from voting further: /stopPoll.

    The argument structure is up to the implementer, but the command will need to take the poll's identifier. This command will mark a poll as inactive within the bot, and possibly make other changes to internally stored data as necessary. From the user perspective, this command will simply stop further voting on the poll permanently. The bot should reply with a confirmation that the poll was closed. Only the poll creator or an admin should be able to close a poll.

    /vote Command

    Create a command which will allow a user to vote in an existing poll: /vote.

    This command should allow users to vote in a poll by passing the poll's identifier and their responses via command arguments in a DM to the bot. It would be ideal if the votes were stored anonymously. A conflicting, yet also desirable, feature would be allowing users to amend their votes. Methods to accomplish both likely exist, and might use some kind of hashing - feel free to suggest ideas in this thread. The bot should acknowledge the vote and repeat the responses back to the user.

    /seePoll

    Create a command which will allow users to see the results of a poll: /seePoll.

    This command should allow users to see a poll's result by passing the poll's identifier. After receiving the command, the bot should reply with a response showing the tabulated results of the poll in an easily readable format. It might be best to offer a "verbose" argument which will make the bot provide a more in depth analysis of the results.

    /polls

    Create a command which will allow users to see active and inactive polls: /polls.

    This command will reply with a readable list of all polls with their statuses: inactive or active. This is simply a way for users to see what polls are available to interact with.

    enhancement 
    opened by awhigham9 2
  • Awhigham9/improve command importing

    Awhigham9/improve command importing

    Change how commands.ts loads all commands at runtime to be more readable and extensible.

    Previously, commands.ts would load all commands by importing all modules under src/commands/ and assuming the default import from a module is the command. That is, any file in src/commands/ must adhere to the following strict structure where the default export must be a command:

    const foo: ICommand  = {
        // code
    }
    
    export default foo;
    

    This has two negative effects. First, this is not readable and makes the later import in the KV store in commands.ts non-obvious. Second, it is not extensible because it prevents files under src/commands/ from being able to export default items which are not commands and makes it impossible for a single file to export multiple commands. Either of these may be desirable in the future.

    The proposed solution is to have files which offer commands to commands.ts export a function called getCommands. This name is standard across the code base. This solves the first issue by making the intended goal of the function explicit, and it solves the second by allowing variable default exports and multiple command exports.

    It looks like this:

    const foo: ICommand  = {
        // code
    }
    
    export function getCommand(): ICommand[] {
        return [foo];
    }
    

    A multiple command export could have a multi-item list in the return statement.

    opened by awhigham9 1
  • Parametrize hard-code, privileged 'officer' role in roles.ts

    Parametrize hard-code, privileged 'officer' role in roles.ts

    Currently, roles.ts assumes the presence of a role with name officer and gives this role privileged status. This could be an issue if other servers try to use the bot, or the bot is horizontally scaled to work on multiple servers.

    Instead, a config variable should be added which stores the privileged role for the role management commands. The variable can be stored in config.json or another configuration file. Perhaps if the value is undefined, only the administrator role (which is server agnostic) is privileged.

    opened by awhigham9 0
  • Hello World Command

    Hello World Command

    Add a command which provides users with the hello world code for different programming languages.

    Command Syntax: /helloworld [language]

    Example: User runs /helloworld java Bot Responds:

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
        }
    }
    
    enhancement good first issue 
    opened by awhigham9 0
  • Cut down on lootbox bloat

    Cut down on lootbox bloat

    In animals.json, there are a lot of emoji that aren't particularly interesting to get from the lootbox. I think we should cut down on a lot of the dumb / uninteresting ones, and only keep the particularly interesting animals / food.

    good first issue 
    opened by cbloodsworth 0
  • Improve UI for commands

    Improve UI for commands

    convert messages for commands into embeds for user.ts and server.ts discord.js embed docs: https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor

    enhancement 
    opened by devp4 0
  • Enhanced Polling

    Enhanced Polling

    Extend polling commands with more features and polish.

    This includes:

    • Timed Polls
    • Single-vote Polls (enforce only 1 vote per discord user)
    • Improved user interface for polls (both command structure and poll displays)
    • Multi-question polls
    enhancement 
    opened by awhigham9 0
  • Better Linting

    Better Linting

    We need to specify some stricter linting rules. There is no specific set of rules in mind, but any more comprehensive rule-set from the TypeScript development community would probably do.

    We also need to add a npm run lint and npm run lint-fix command to the package.json. These should be:

    "scripts": {
      // other commands. . .
      "lint": "eslint . --ext .ts,.tsx",
      "lint-fix": "eslint . --ext .ts,.tsx --fix"
     }
    

    Lastly, we should add a PR workflow check which runs linting and blocks the PR till linting passes.

    enhancement 
    opened by awhigham9 0
  • Reddit Scraper Command

    Reddit Scraper Command

    Write a command which grabs the top post off of a subreddit on Reddit. The initial version could just work for a particular subreddit if that's easier. Good candidates are r/programmerhumor or r/programming.

    Command Syntax: /toppost [subreddit name]

    enhancement 
    opened by awhigham9 1
Owner
UF Open Source Club
Open Source Club at the University of Florida
UF Open Source Club
Successor of the flowchart-fun syntax. Store tabular data and graph information in the same document.

graph-selector-syntax A syntax for storing graphs and tabular data in plain text View Examples Installation npm install graph-selector Usage import {

Tone Row 32 Dec 15, 2022
Team Alpha Super Awesome Cool Dynamite Wolf Squadron - 10 - Project 1

Super Hero Wiki This is a group project for our Interactive Front End Web Site. We created a Super Wiki that uses two (2) APIs to provide users a comi

Vicente Garcia Sepulveda 3 Mar 24, 2022
🤖A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable

Tic-Tac-Toe AI A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable How it Works Tic-Tac-Toe is what is k

Martin 4 May 20, 2022
A full documentation on everything we know about Alpha 1.0.16 versions.

Minecraft's Alpha 1.0.16 Versions Before you start, make sure to watch RetroGamingNow's video about this first. Highly influenced (technically a port

_NexTre_ 44 Dec 23, 2022
ALPHA build of re621 2.0

RE621 is a comprehensive project created to improve the basic user experience while browsing e621.net. It consists of several different modules that e

re621 11 Dec 16, 2022
The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra

Remix Fakebooks App This is a (very) simple implementation of the fakebooks mock app demonstrated on remix.run. There is no database, but there is an

Kent C. Dodds 61 Dec 22, 2022
Simple webpack plugin that generates VERSION and commitInfo insert index.html during build

Html commit version plugin Simple webpack plugin that generates CommitInfo and VERSION insert index.html during build. English | 简体中文 Usage Given a we

null 13 Mar 8, 2022
A simple rocketchat version for apple silicon

Why develop this version? Rocket. Chat Electron does not have Mac (Apple Silicon) version at present, so it has a poor use experience. After compiling

vast zhao 9 Sep 19, 2021
It maintains my version of js notes which I learned from the famous Namaste Javascript Youtube Series by Akshay Saini.

Welcome to Namaste Javascript Notes ?? ❓ what it is This repo maintains my version of javascript notes which I learned from the famous Namaste Javascr

Alok Raj 682 Jan 4, 2023
ScraperTools BETA Version 1.0.1

ScraperTools Official ScraperTools NPM Package Get Started Via NPM: $ npm install scraper-tools Cara Menggunakan const scrapertools = require('scraper

Zahir Hadi Athallah 21 Sep 28, 2022
The Third (and hopefully last) Version Of The Beatshape API!

Beatshape API V3 This is The Third (and hopefully last) Version Of The Beatshape API! How To Run: Install Node.js Clone This Repo git clone https://gi

CDX Team 1 Dec 25, 2021
Make sure a specific version and package-manger to be used in project.

pm-keeper A simple way to force package-manager in your project. usage Add a preinstall script in your project's package.json, link this: { "scripts

阿五 13 Sep 25, 2022
An unofficial, simplified version of the @Shopify/koa-shopify-auth middleware library.

simple-koa-shopify-auth https://www.npmjs.com/package/simple-koa-shopify-auth NOTE: This package is not maintained by or affiliated with Shopify. Desc

David 20 Nov 7, 2022
ES6 version of tween.js

es6-tween This project development suspended due of no support from community and no financial support to author High-performant animations without he

tween.js and related projects 180 Nov 30, 2022
Free & Open Source Version of Kneaver Thinking Box

kneaver-open Free & Open Source Version of Kneaver Thinking Box This is a very initial submission. barely more than a boilerplate. There is no warrant

Kneaver Corp 5 Jan 17, 2022
Firebase SDK 9 + Google Sign In + Chrome Extension Manifest Version 3 + Webpack

Firebase SDK 9 + Google Sign In + Chrome Extension Manifest Version 3 + Webpack Demo Find this Chrome Extension Setup and working demo here or on Yout

Rasika Warade 40 Dec 28, 2022
Reliactyl - Reliactyl Client Premium Version

Reliactyl Reliactyl Client Premium Version Features - Allows users to split reso

Reliactyl Development 12 Feb 24, 2022
Directus Hook Extension: Version Control Changelog

A Directus hook extension to push user written change summaries (from a singleton collection text field) to a changelog in a VCS server

BIX Digital Lab 11 Nov 27, 2022
Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region

Run Any Node.js Version in AWS Lambda Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region. We add support f

Fusebit 116 Dec 15, 2022