-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**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
Showing
31 changed files
with
595 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
* | ||
!*.ts | ||
* | ||
!*.ts | ||
!*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.