Skip to content

Commit

Permalink
New Version (2.2.0) (#12)
Browse files Browse the repository at this point in the history
**New in version 2.2.0**  
- Switched data storage to [MongoDB](https://www.mongodb.com/)
- Published a new Docker image, learn more at the [Docker Docs](https://docs.docker.com/get-docker/)
- Lots and lots and lots of bug fixes
- Added code formatting, dependency checking, basic ci/cd and more

### Admin Commands
- `/createRoles` - Modified to work without a reboot or copying to an `.env` file
- `/csClassPoll` - Create the poll that will allow students to select their cs classes 

## Pull Requests Merged
* Rewrite of CSSC-bot in Typescript using Discord.js and WOKCommands (Part 1-5) by @nathen418 in #1
* merge wip  by @schiltz3 in #3
* merge wip 2 by @schiltz3 in #4
* Rework Menu creation by @schiltz3 in #5
* Merged csClassPoll and csClassTest by @schiltz3 in #8
* Delay by @schiltz3 in #9
* send up to 5 menus per message by @schiltz3 in #10
* switch to using class CODE as key rather than suuid by @schiltz3 in #11


**Full Changelog**: v2.1.0...v2.2.0
  • Loading branch information
nathen418 authored Sep 1, 2022
2 parents fc227b1 + 753dce8 commit 58f06d4
Show file tree
Hide file tree
Showing 31 changed files with 595 additions and 263 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '19 8 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
18 changes: 18 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
40 changes: 20 additions & 20 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Format
on:
pull_request:
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v2
with:
node-version: ">=16.13.2"
- run: npm ci
- run: npm run format
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply auto formatting changes
branch: ${{ github.head_ref }}
name: Format
on:
pull_request:
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v2
with:
node-version: ">=16.13.2"
- run: npm ci
- run: npm run format
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply auto formatting changes
branch: ${{ github.head_ref }}
23 changes: 23 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Docker image to GitHub Package Registry
on:
push:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Copy Repo Files
uses: actions/checkout@master

#This Action Emits 2 Variables, IMAGE_SHA_NAME and IMAGE_URL
#which you can reference in subsequent steps
- name: Publish Docker Image to GPR
uses: machine-learning-apps/gpr-docker-publish@master
id: docker
with:
IMAGE_NAME: 'cssc-bot'
TAG: 'latest'
DOCKERFILE_PATH: './Dockerfile'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*
!*.ts
*
!*.ts
!*/
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ COPY . .

RUN npm install -g typescript ts-node

CMD [ "ts-node", "index.ts" ]
CMD [ "ts-node", "index.ts" ]

LABEL org.opencontainers.image.source="https://github.com/Antares-Network/CSSC-Bot"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Lisa Isaeva

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Follow this link in a browser, and choose the private server you created to add
### Run from source

```bash
git clone https://github.com/llisaeva/CSSC-Bot.git
git clone https://github.com/Antares-Network/CSSC-Bot.git
# Fill out the .env file using the template in .env.template
npm install
npm install -g typescript ts-node
Expand All @@ -70,7 +70,7 @@ ts-node index.ts
### Run from Docker

```bash
git clone https://github.com/llisaeva/CSSC-Bot.git
git clone https://github.com/Antares-Network/CSSC-Bot.git
# Fill out the .env file using the template in .env.template;
# Or add the environment variables to your docker run command by adding the
# --env-file .env option
Expand Down Expand Up @@ -119,3 +119,8 @@ The bot should become responsive. You can check for errors in the console.
- [WOKcommands Docs](https://docs.wornoffkeys.com/)
- [AntaresBot Codebase](https://playantares.com/antaresbot)
- [Antares Status Tracking](https://status.playantares.com/)

## Credits

- [Lisa Isaeva](https://github.com/llisaeva)
- [Nate Goldsborough](https://github.com/nathen418)
12 changes: 7 additions & 5 deletions commands/owner/createRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ export default {
chalk.red("------------------------------------------------------")
);
// Create the roles
createRoles(interaction.guild!, 0);
createRoles(interaction.guild!, 1);
interaction.reply(
"Roles created! Check the console for the role IDs\nPaste the output into your .env file and restart the bot\n "
);
createRoles(interaction.guild!, "class");
createRoles(interaction.guild!, "staff");
createRoles(interaction.guild!, "year");
interaction.reply({
content: "Roles created!",
ephemeral: true,
});

// Log the command usage
console.log(
Expand Down
112 changes: 112 additions & 0 deletions commands/owner/csClassPoll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {
MessageEmbed,
MessageActionRow,
MessageSelectMenu,
MessageSelectOptionData,
} from "discord.js";
import chalk from "chalk";
import { ICommand } from "wokcommands";
import classModel from "../../models/classModel";
import { checkForRoles } from "../../rolesOps";

export interface Class {
CODE: string;
TITLE: string;
INFO: string;
ROLE_NAME: string;
ROLE_ID: string;
UUID: string;
}

export default {
name: "csClassPoll",
category: "owner",
description: "Posts the CS Class Poll",
slash: true,
testOnly: false,
guildOnly: true,
requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"],
ownerOnly: true,

callback: async ({ client, interaction: msgInt }) => {
if (!checkForRoles(msgInt.guild!)) {
msgInt.reply(
"Please run the `/ createRoles` command in this server to create the necessary roles for this poll!"
);
return;
}

let classes: Class[] = await classModel.find({}).sort({ CODE: 1 });
const class_chunks = split_list(classes, 25);

let rows: MessageActionRow[] = [];
for (let index = 0; index < class_chunks.length; index++) {
const menu = new MessageSelectMenu();
menu.setCustomId(`csClassPoll+${index}`);
// menu.setMinValues(1); //!Add this later when the bot is able to handle multiple selections at once
// menu.setMaxValues(10);
menu.setPlaceholder("Select an option");
// create a new list of options from the classes and add to menu
menu.addOptions(class_chunks[index].map(create_option_from_class));

// Add single message to action row
const row = new MessageActionRow();
row.addComponents(menu);
rows.push(row);
}

const row_chunks = split_list(rows, 5);
for (let index = 0; index < row_chunks.length; index++) {
if (index == 0) {
// Define embeds used in this command
const infoEmbed = new MessageEmbed()
.setTitle("Choose a role")
.setColor("#0099ff")
.setDescription(
"Select the option(s) with your current COMPSCI classes."
)
.setFooter({
text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`,
iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg",
});

msgInt.reply({ embeds: [infoEmbed], components: row_chunks[index] });
} else {
msgInt.channel!.send({ components: row_chunks[index] });
}
// await on a new promise that resolves itself after a delay of 200 ms
await new Promise((resolve) => {
setTimeout(resolve, 200);
});
}

// Log the command usage
console.log(
chalk.blue(
`${chalk.green(`[COMMAND]`)} ${chalk.yellow(
msgInt.user.tag
)} used the ${chalk.green(`/csclasspoll`)} command in ${chalk.yellow(
msgInt.guild?.name
)}`
)
);
},
} as ICommand;

// Splits any size list into lists of at most `max_list_len`
function split_list(list: Array<any>, max_list_len: number) {
let class_chunks = [];
for (let i = 0; i < list.length; i += max_list_len) {
class_chunks.push(list.slice(i, i + max_list_len));
}
return class_chunks;
}

// consumes a Class and returns Message Selec tOption data
function create_option_from_class(_class: Class): MessageSelectOptionData {
return {
label: _class.CODE,
value: _class.CODE,
description: _class.TITLE,
};
}
2 changes: 1 addition & 1 deletion commands/owner/staffPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
);

// Send the embed and message component rows
if (!checkForRoles(msgInt.guild!, 1)) {
if (!checkForRoles(msgInt.guild!)) {
msgInt.reply(
"Please run the `/createRoles` command in this server to create the necessary roles for this poll!"
);
Expand Down
Loading

0 comments on commit 58f06d4

Please sign in to comment.