Skip to content

Commit

Permalink
Minor version update | 2.2.0 --> 2.2.1 (#27)
Browse files Browse the repository at this point in the history
## New in version 2.2.1
- Many more bugfixes, dependency updates
- Added contributing standards and pull request templates
- Added interfaces and strong typing to all database calls
- Updated workflows to work on the correct branches
- Refined branch protection rules to make collaboration easier

## Merged Pull Requests
* Update README.md by @nathen418 in #14
* Create dependabot.yml by @nathen418 in #15
* Bump chalk from 4.1.2 to 5.0.1 by @dependabot in #18
* Bump mongoose from 6.5.3 to 6.5.4 by @dependabot in #16
* Nathen418/update dependabot by @nathen418 in #19
* merge main into staging by @nathen418 in #20
* update what branches workflows to run on correct branches and triggers by @schiltz3 in #24
* Add Contributing Standards  by @nathen418 in #25
* PR template by @schiltz3 in #26
* Add interfaces for models by @schiltz3 in #22
* Fix bug in `addNewRole` by @schiltz3 in #29
* Bugfix/schiltz3/deepsource by @schiltz3 in #28

## New Contributors
* @dependabot made their first contribution in #18

**Full Changelog**: v2.2.0...v2.2.1
  • Loading branch information
nathen418 authored Sep 7, 2022
2 parents 04e77ce + 718c5f7 commit 6e40e09
Show file tree
Hide file tree
Showing 31 changed files with 280 additions and 183 deletions.
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Descriptive title

A person with no idea what task you were working on before should at least
have an idea as to what you did.

# Link to github card
Type `#` to see list of autolinks to pull requests or issues

# Changes
The body should contain a high-level overview of the individual changes you made, what parts of the application you changed, etc.
This may be in list form.


*
*
*


You may also wish to include links to related pull requests, issues, or branches which may affect your changes.
You can mention people by using `@`
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
interval: "daily"
target-branch: "staging"
8 changes: 3 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
#
name: "CodeQL"

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

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# 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]
on:
pull_request:
branches: [main, staging]

permissions:
contents: read
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Docker Image CI

on:
push:
branches: [ "main, staging" ]
on:
push:
pull_request:
branches: [ "main, staging" ]
branches: [ main, staging ]

jobs:

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Format
on:
pull_request:
branches: ['*', '!main']
jobs:
format:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish Docker image to GitHub Package Registry
on:
push:
branches: [ "main" ]
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/__pycache__
.vscode
.env
*.env
node_modules
unused-commands
d.py/
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CSSC-bot Contributing guidelines

## Developing New Features

First create a new branch with it's base set to the [staging](https://github.com/Antares-Network/CSSC-Bot/tree/staging) branch.
For naming conventions use `feature/GithubUsername/FeatureName`. Example: `feature/nathen418/mongodb-support`
Next when your feature is ready to be merged, submit a pull request to the [staging](https://github.com/Antares-Network/CSSC-Bot/tree/staging) branch.
This will be used to test your changes along side the rest of the code and any other pending new features.

## Fixing Bugs

Do the same as the instructions except when naming your branch use the naming convention: `bugfix/GithubUsername/BugName`. Example: `bugfix/nathen418/fix-api-connection-err`

## Editing/Merging Pull Requests

Only merge pull requests you authored or have been approved by the author to merge.

## Pushing to branches

Only push to branches you have been given permission to push to. This means that you should only commit to branches that have your name in the branch name unless the branch owner has given you permission to push to it.
18 changes: 10 additions & 8 deletions commands/owner/createRoles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ICommand } from "wokcommands";
import { createRoles } from "../../rolesOps";
import chalk from "chalk";
import { classModel } from "../../models/classModel";
import { staffModel } from "../../models/staffModel";
import { yearModel } from "../../models/yearModel";

export default {
name: "createRoles",
Expand All @@ -13,18 +16,17 @@ export default {
ownerOnly: true,

callback: async ({ interaction }) => {
console.log(
chalk.green(
"Creating roles...\nCopy and paste the following output into your .env file"
)
);
console.log(chalk.green("Creating roles..."));
console.log(
chalk.red("------------------------------------------------------")
);
if (interaction.guild === null) {
return;
}
// Create the roles
createRoles(interaction.guild!, "class");
createRoles(interaction.guild!, "staff");
createRoles(interaction.guild!, "year");
await createRoles(interaction.guild, classModel);
await createRoles(interaction.guild, staffModel);
await createRoles(interaction.guild, yearModel);
interaction.reply({
content: "Roles created!",
ephemeral: true,
Expand Down
61 changes: 27 additions & 34 deletions commands/owner/csClassPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import {
} from "discord.js";
import chalk from "chalk";
import { ICommand } from "wokcommands";
import classModel from "../../models/classModel";
import { classModel, IClass } from "../../models/classModel";
import { checkForRoles } from "../../rolesOps";
import { sleep } from "../../util";

export interface Class {
CODE: string;
TITLE: string;
INFO: string;
ROLE_NAME: string;
ROLE_ID: string;
UUID: string;
// Splits any size list into lists of at most `max_list_len`
function split_list<T>(list: T[], max_list_len: number): T[][] {
const class_chunks: T[][] = [];
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: IClass): MessageSelectOptionData {
return {
label: _class.CODE,
value: _class.CODE,
description: _class.TITLE,
};
}
export default {
name: "csClassPoll",
category: "owner",
Expand All @@ -29,17 +38,21 @@ export default {
ownerOnly: true,

callback: async ({ client, interaction: msgInt }) => {
if (!checkForRoles(msgInt.guild!)) {
if (msgInt.guild === null) {
console.log(chalk.red("No guild"));
return;
}
if (!(await 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 classes = await classModel.find({}).sort({ CODE: 1 });
const class_chunks = split_list(classes, 25);

let rows: MessageActionRow[] = [];
const rows: MessageActionRow[] = [];
for (let index = 0; index < class_chunks.length; index++) {
const menu = new MessageSelectMenu();
menu.setCustomId(`csClassPoll+${index}`);
Expand Down Expand Up @@ -72,12 +85,10 @@ export default {

msgInt.reply({ embeds: [infoEmbed], components: row_chunks[index] });
} else {
msgInt.channel!.send({ components: row_chunks[index] });
msgInt.reply({ 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);
});

await sleep(200);
}

// Log the command usage
Expand All @@ -92,21 +103,3 @@ export default {
);
},
} 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,
};
}
6 changes: 5 additions & 1 deletion commands/owner/staffPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ export default {
)
);

if (msgInt.guild === null) {
console.log(chalk.red("No guild"));
return;
}
// Send the embed and message component rows
if (!checkForRoles(msgInt.guild!)) {
if (!(await checkForRoles(msgInt.guild))) {
msgInt.reply(
"Please run the `/createRoles` command in this server to create the necessary roles for this poll!"
);
Expand Down
10 changes: 7 additions & 3 deletions commands/owner/yearPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@ export default {
)
);

if (msgInt.guild === null) {
console.log(chalk.red("No guild"));
return;
}
// Send the embed and message component rows
if (!checkForRoles(msgInt.guild!)) {
msgInt.reply({
if (!(await checkForRoles(msgInt.guild))) {
await msgInt.reply({
content:
"Please run the /createRoles command in this server to create the necessary roles for this poll!",
ephemeral: true,
});
} else {
msgInt.reply({ embeds: [infoEmbed], components: [row] });
await msgInt.reply({ embeds: [infoEmbed], components: [row] });
}

// Log the command usage
Expand Down
9 changes: 6 additions & 3 deletions commands/user/clear.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import chalk from "chalk";
import { GuildMember } from "discord.js";
import { ICommand } from "wokcommands";
import { classModel } from "../../models/classModel";
import { staffModel } from "../../models/staffModel";
import { yearModel } from "../../models/yearModel";
import { removeRole } from "../../rolesOps";

export default {
Expand All @@ -16,9 +19,9 @@ export default {
// Remove roles from user
if (!interaction.member) return;
const member = interaction.member as GuildMember;
removeRole(member, "class");
removeRole(member, "year");
removeRole(member, "staff");
await removeRole(member, classModel);
await removeRole(member, yearModel);
await removeRole(member, staffModel);
// Reply to the user
interaction.reply({
content: "Cleared all roles that I have assigned to you.",
Expand Down
2 changes: 1 addition & 1 deletion commands/user/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
.setDescription(description)
.setFooter({ text: footer, iconURL: footerIcon });

interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
2 changes: 1 addition & 1 deletion commands/user/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
.setDescription(description)
.addFields(fields)
.setFooter({ text: footer, iconURL: footerIcon });
interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
2 changes: 1 addition & 1 deletion commands/user/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
.setFooter({ text: footer, iconURL: footerIcon });

// Return the embed
interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
2 changes: 1 addition & 1 deletion commands/user/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
.setDescription(description)
.setFooter({ text: footer, iconURL: footerIcon });

interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
10 changes: 3 additions & 7 deletions commands/user/uptime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk";
import { MessageEmbed, TextChannel } from "discord.js";
import { MessageEmbed } from "discord.js";
import { ICommand } from "wokcommands";

export default {
Expand All @@ -12,12 +12,8 @@ export default {
requiredPermissions: ["SEND_MESSAGES"],

callback: async ({ client, interaction }) => {
// Command information
const id = interaction.user.id;
const chan = interaction.channel as TextChannel;

// Computed values
const time = client.uptime!;
const time = client.uptime !== null ? client.uptime : 0;
const days = Math.floor(time / 86400000);
const hours = Math.floor(time / 3600000) % 24;
const minutes = Math.floor(time / 60000) % 60;
Expand All @@ -38,7 +34,7 @@ export default {
.setFooter({ text: footer, iconURL: footerIcon });

// Return the embed
interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
2 changes: 1 addition & 1 deletion commands/user/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
.setFooter({ text: footer, iconURL: footerIcon });

// Return the embed
interaction.reply({ embeds: [Embed] });
await interaction.reply({ embeds: [Embed] });

// Log the command usage
console.log(
Expand Down
Loading

0 comments on commit 6e40e09

Please sign in to comment.