Skip to content

Commit f3fe5e4

Browse files
Domin0deimagine-hussaintuneinzcDay1AcdSoftCo
authored
Update Production Bot from QA Bot (#202)
* migrate from insou api to circles for the handbook commands (#128) * migrate from insou api to circles for the handbook commands * remove trailing forward slash in handbook.json * handbook: the handbook is fixed * Update handbook.js commented out a console.log --------- Co-authored-by: tunein <[email protected]> Co-authored-by: zcDay1 <[email protected]> * prettier formatted * chore(deps): update `renovate` config * chore(deps): update docker/build-push-action action to v4 (#134) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Projects description command feature (#145) * projects-descriptions v1 commit * project-descriptions command v2 commit * linting fixes for project-descriptions.js, and for handbook.js --------- Co-authored-by: AcdSoftCo <[email protected]> * disable annoying carrotboard pins * rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before merging * Revert "rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before merging" This reverts commit 2f59c71. * rolesPermOverride command (#152) * rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before mergin * BUGGY CODE but still progress over the previous commit, I will come back this evening to fix * rolesPermOverride command: now admin-only command, and I've tested it for various cases regarding if a channel exists, if a role exists for a channel that doesnt exist, if there are two channels with the same name as a role and vice versa, and it works without error --------- Co-authored-by: AcdSoftCo <[email protected]> * Roles perm override (#153) * rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before mergin * BUGGY CODE but still progress over the previous commit, I will come back this evening to fix * rolesPermOverride command: now admin-only command, and I've tested it for various cases regarding if a channel exists, if a role exists for a channel that doesnt exist, if there are two channels with the same name as a role and vice versa, and it works without error * course.js: removed code to create individual user permission overwrites in each channel --------- Co-authored-by: AcdSoftCo <[email protected]> * Project descriptions (#154) * project-descriptions.js: updated course descriptions written by the directors for 2023 levelling up with Projects Fair Day, and the discord bot CTF flag easter egg entry under this command included too for this event. * made messages ephemeral to prevent chat from being spammed by users. And got rid of link embeds in the messages. * lint update --------- Co-authored-by: AcdSoftCo <[email protected]> * Dev/course channel fix 3 (#158) * course-chat-fix-2, make new roles where there arent any in /rolespermoverride and also remove individual permission overwrites, and also updates to /course join to catch when there doesn't exist a role for a course and also /course leave to attempt to remove individual permission overwrites along with removing course role PLEASE TEST THOROUGHLY AND INSPECT CODE THOROUGHLY. I wrote this ASAP and haven't got time to properly review it. * Modified functions for course channel fixes * Check for if user only has read perms for overwrite replacing and fix looping over members * Fix to functionality of iteration and editing roles * Fix to initial working state * Fix linting * Additional fixes to ordering and component operations to remove role and individual permissions correctly * Appended filter for both view only perms and view + send messages perms --------- Co-authored-by: AcdSoftCo <[email protected]> Co-authored-by: Wolfdragon24 <[email protected]> * dev/course-channel-fix-5 (#160) * course-chat-fix-2, make new roles where there arent any in /rolespermoverride and also remove individual permission overwrites, and also updates to /course join to catch when there doesn't exist a role for a course and also /course leave to attempt to remove individual permission overwrites along with removing course role PLEASE TEST THOROUGHLY AND INSPECT CODE THOROUGHLY. I wrote this ASAP and haven't got time to properly review it. * Modified functions for course channel fixes * Check for if user only has read perms for overwrite replacing and fix looping over members * Fix to functionality of iteration and editing roles * Fix to initial working state * Fix linting * Additional fixes to ordering and component operations to remove role and individual permissions correctly * Appended filter for both view only perms and view + send messages perms * Appended single channel mode for permissions override * Appended check command for role permissions * Resolved merge conflicts in dev/course-channel-fix-4 --------- Co-authored-by: AcdSoftCo <[email protected]> Co-authored-by: Wolfdragon24 <[email protected]> * Update rolesPermOverride.js double equals updated to triple equals on line 156 * Course Command Fixing - Collection Null Value Error (#162) * Accounting for non-channel returns associated to snowflakes * Utilise cache directly as fetch falls back to a cache call anyway * Dev/upgrade handbook url (#164) * Upgraded handbook url in config.json to use 2024. Also fixed incorrect url links in the handbook.js command. * Fixed eslint warnings * Fixed bug for courses that do not yet have an offering term (Default: "None") (#165) * Upgraded handbook url in config.json to use 2024. Also fixed incorrect url links in the handbook.js command. * Fixed eslint warnings * Fixed equivalent courses urls being listed * Implementation of the Lunch Buddy feature (#167) * update: checking if perms work * Chron job set for every minute, basic embed added and structure for the locations and sub locations created * Updated README * Implemented area voting system * Ran linting and prettier for current changes * Appending location poll for given area, and vote counting for both area and locations * Implemented functional voting system for area and location, creating thread upon completion of set * Used await and cleaned up a bit of code, thread now adds all voters not only the ones who voted for the winning area * Lint fix * Removed promises and adjusted placement of vote function calls * Adjusted thread users, append location vote pings * Linting fixes * Locations Update * Adds "any" option and append additional vote info * Appended code for live run timing * Update to use config file * Allow disabling of feature without editing code and disable * Minor adjustment to readme and npm commands * Appended clarifying comment regarding edge case of only any votes --------- Co-authored-by: mi-mott <[email protected]> * [DISC-107] Adding csesocLinks to get CSESoc related links (#170) * completed csesocLinks command * linting * Refactor execute function to use arrow functions * linting * [DISC-109] Adding bot-status for events and member count (#169) * Adding bot-status for events and member count * Fixing lint errors * Adding fixes to how member count is calculated --------- Authored-by: Eric <[email protected]> * Update dependency nodemailer to v6.9.9 [SECURITY] (#168) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency axios to v0.28.0 [SECURITY] (#166) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency yaml to v2.2.2 [security] (#147) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency dotenv to v16 (#141) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update actions/checkout action to v4 (#157) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency discordjs-button-pagination to v3 (#140) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Remove unused discord-tictactoe dependency and updated canvas (#173) * fix(deps): update weekly patch updates (#142) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency @discordjs/builders to v1 (#135) * Update dependency @discordjs/builders to v1 * Update to project description choices to utilise object structure (Fix to erroring on dependency update) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Wolfdragon24 <[email protected]> Co-authored-by: Wolfdragon24 <[email protected]> * fix(deps): update dependency discord.js to v14 (#139) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update to fix v14 breaking changes (#176) * chore(deps): update actions/setup-node action to v4 (#172) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Nitpick refactor for courses command (#126) * I can finally sleep now * Implementation of suggested modifications * Modification to ensure correct regex form for case-insensitive match --------- Co-authored-by: Wolfdragon24 <[email protected]> * fix(deps): update dependency mathjs to v12 (#182) * chore(deps): update docker-github-actions * fix(deps): update dependency mathjs to v12 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency axios to v1 (#181) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency @discordjs/rest to v2 (#179) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency eslint-config-prettier to v9 (#175) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency nodemon to v3 (#183) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update node.js to v20 (#171) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency mathjs to v13 (#184) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * DISC-119-unielectives-review (#188) * working unilectives review * added warning for chartjs dependency * changed to ephemeral reply * removed unneccesary libraries for chartjs * hopefully no npm package conflict dying * npm packages should be fixed * changed web scraper package for robustness * linting * fixed yaml npm issue * JSCode docu * linting * revert config files to og * package-json changes --------- Co-authored-by: addison <[email protected]> * [DISC-120] Update eslint dependency and nodejs to v20 * chore(deps): update dependency eslint to v9 * Update to eslint and babel/eslint-parser * Update lock file * Fixes for linting * Modifications to ignore node modules and consider all other files for linting * Force update of node to version 20 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Wolfdragon24 <[email protected]> * [DISC-120] Update to prettier and corresponding eslint plugin * chore(deps): update dependency prettier to v3 * Update prettier config to use auto end of line setting * Linting and prettifying * Prettier fixes and running format * Prettier fix * Fix by consolidating updates to prettier and eslint plugin --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Wolfdragon24 <[email protected]> * chore(deps): lock file maintenance (#186) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update weekly minor updates (#143) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DISC-120] Fix to renovate.json file (#190) * [DISC-120] Declare file type for requiring data (#192) * [DISC-120] Adjust data type for file (#193) * Declare file type for requiring data * Use json as opposed to js data file * [DISC-120] Move to using fs for configuration (#194) * Declare file type for requiring data * Use json as opposed to js data file * Replace require to use reading file with fs * Move file to config * Fix spelling error * Append setup command for puppeteer browser * Downloading dependencies and requirements for puppeteer * Modification to installation order * Affirm installation * Revert prior changes and set to use alternate folder for chromium instance * Manually ignore puppeteer config file in eslint * Attempt fix to eslint hanging * [DISC-117] Adding travelguides command (#187) * initial travelguide add subcommand * fixing formatting * fixing syntax error * added get function * linting * completed travelguide command * linting * adding deletion confirmation * linting * migrating travelguide.json to postgres * linting * linting --------- Co-authored-by: Jessica Xu <[email protected]> * Modify location and method for chromium install * Alter setup to use chromium base * Update to puppeteer version * Replace secondary node image with puppeteer * Fix capitalisation inconsistency and assume permission set * Reappend entrypoint permission modification * Reset user from image setup * Attempt return to puppeteer user after setup * [DISC-110] Adding Course Chats 1-year "Subscription" (#191) * Added database implementation of user roles when assigned and removed * Added time checking function for expired user_roles and added time assigned column to user_roles table * Added on ready file with cron.js to perform daily check of old_roles * Adding new package cron for scheduling * fixing lint issues * Fixing prettier issues * Package changes * Restoring develop package lock.json and fixing db_ready * Moving guild and roles out of for loop to remove redundant fetching * [DISC-121] Implement Logging for User Rejoining (#199) * Implementation of user join and leave logging and admin command to facilitate replacing old db table * Complete implementation of rejoin notices * Fix to incorrect conflict resolution commit --------- Co-authored-by: imagine-hussain <[email protected]> Co-authored-by: tunein <[email protected]> Co-authored-by: zcDay1 <[email protected]> Co-authored-by: AcdSoftCo <[email protected]> Co-authored-by: Jared L <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: abiramen <[email protected]> Co-authored-by: Bigbugman <[email protected]> Co-authored-by: Abraham Assariparambil Earnest <[email protected]> Co-authored-by: mi-mott <[email protected]> Co-authored-by: chlowoee <[email protected]> Co-authored-by: ericwu2205 <[email protected]> Co-authored-by: XenocidePC <[email protected]> Co-authored-by: h34312575s <[email protected]> Co-authored-by: addison <[email protected]> Co-authored-by: Jessica Xu <[email protected]>
1 parent 3bf3a61 commit f3fe5e4

File tree

4 files changed

+111
-80
lines changed

4 files changed

+111
-80
lines changed

commands/admin.js

+7-78
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,7 @@ const { SlashCommandBuilder } = require("@discordjs/builders");
22
const { Permissions } = require("discord.js");
33

44
const COMMAND_KICKUNVERIFIED = "kickunverified";
5-
const COMMAND_MIGRATE = "migratecourses";
6-
const COMMAND_REMOVECOURSEROLES = "nukeremovecourseroles";
7-
8-
// yeah i know this code is copy pasted from the other file
9-
// but whatever, the migration command is temporary!
10-
const is_valid_course = (course) => {
11-
const reg_comp_course = /^comp\d{4}$/;
12-
const reg_math_course = /^math\d{4}$/;
13-
const reg_binf_course = /^binf\d{4}$/;
14-
const reg_engg_course = /^engg\d{4}$/;
15-
const reg_seng_course = /^seng\d{4}$/;
16-
const reg_desn_course = /^desn\d{4}$/;
17-
18-
return (
19-
reg_comp_course.test(course.toLowerCase()) ||
20-
reg_math_course.test(course.toLowerCase()) ||
21-
reg_binf_course.test(course.toLowerCase()) ||
22-
reg_engg_course.test(course.toLowerCase()) ||
23-
reg_seng_course.test(course.toLowerCase()) ||
24-
reg_desn_course.test(course.toLowerCase())
25-
);
26-
};
5+
const COMMAND_DROPUSERTABLE = "dropusertable";
276

287
module.exports = {
298
data: new SlashCommandBuilder()
@@ -36,19 +15,8 @@ module.exports = {
3615
)
3716
.addSubcommand((subcommand) =>
3817
subcommand
39-
.setName(COMMAND_MIGRATE)
40-
.setDescription("Migrates a course role to permission overwrites.")
41-
.addStringOption((option) =>
42-
option
43-
.setName("course")
44-
.setDescription("Course role to remove")
45-
.setRequired(true),
46-
),
47-
)
48-
.addSubcommand((subcommand) =>
49-
subcommand
50-
.setName(COMMAND_REMOVECOURSEROLES)
51-
.setDescription("WARNING: Removes course roles from the server."),
18+
.setName(COMMAND_DROPUSERTABLE)
19+
.setDescription("Deletes the user table and reliant tables."),
5220
),
5321
async execute(interaction) {
5422
try {
@@ -93,50 +61,11 @@ module.exports = {
9361
});
9462
});
9563
return await interaction.reply("Removed unverified members.");
96-
} else if (interaction.options.getSubcommand() === COMMAND_MIGRATE) {
97-
const course = interaction.options.getString("course");
98-
if (!is_valid_course(course)) {
99-
return await interaction.reply("Error: invalid course.");
100-
}
101-
102-
const role = await interaction.guild.roles.cache.find(
103-
(course_role) => course_role.name.toLowerCase() === course.toLowerCase(),
104-
);
105-
106-
if (role === undefined) {
107-
return await interaction.reply("Error: no role exists for course " + course);
108-
}
109-
110-
const channel = await interaction.guild.channels.cache.find(
111-
(role_channel) => role_channel.name.toLowerCase() === role.name.toLowerCase(),
112-
);
113-
114-
if (channel === undefined) {
115-
return await interaction.reply("Error: no channel exists for course " + course);
116-
}
117-
118-
await interaction.deferReply();
119-
for (const member of role.members.values()) {
120-
await channel.permissionOverwrites.create(member, {
121-
VIEW_CHANNEL: true,
122-
});
123-
}
124-
return await interaction.editReply(
125-
"Migrated course role to permission overwrites.",
126-
);
127-
} else if (interaction.options.getSubcommand() === COMMAND_REMOVECOURSEROLES) {
128-
// get all roles, and find courses which match the regex
129-
const course_roles = await interaction.guild.roles.cache.filter((role) =>
130-
is_valid_course(role.name),
131-
);
132-
133-
await interaction.deferReply();
134-
135-
for (const role of course_roles.values()) {
136-
await role.delete();
137-
}
64+
} else if (interaction.options.getSubcommand() === COMMAND_DROPUSERTABLE) {
65+
const userDB = global.userDB;
66+
await userDB.drop_table();
13867

139-
return await interaction.editReply("Removed all course roles.");
68+
return await interaction.editReply("Deleted user table.");
14069
}
14170

14271
return await interaction.reply("Error: unknown subcommand.");

events/guildMemberAdd.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { Events } = require("discord.js");
2+
3+
const CSESOC_SERVER_ID = "693779865916276746";
4+
const REPORT_CHANNEL_ID = "1270283342176059443";
5+
6+
module.exports = {
7+
name: Events.GuildMemberAdd,
8+
once: false,
9+
execute(member) {
10+
/** @type {DBuser} */
11+
const userDB = global.userDB;
12+
13+
// Get report channel
14+
if (member.user.bot || member.user.system || member.guild.id !== CSESOC_SERVER_ID) return;
15+
16+
// Get old user info before joining
17+
userDB.get_user_info(member.id).then((user_data) => {
18+
userDB.user_join(member.id).then((joinType) => {
19+
if (joinType === "rejoin") {
20+
// Fetch the channel to output details
21+
const reportChannel = member.guild.channels.cache.get(REPORT_CHANNEL_ID);
22+
23+
// Fetch formatted date values from joining and leaving events
24+
const joinDate = user_data.joinDate.toLocaleDateString("en-AU");
25+
const leaveDate = user_data.leaveDate.toLocaleDateString("en-AU");
26+
27+
reportChannel.send(
28+
`${member.user} (${member.user.tag}) has rejoined the server. [Last in server: ${leaveDate}, Last joined: ${joinDate}]`,
29+
);
30+
}
31+
});
32+
});
33+
},
34+
};

events/guildMemberRemove.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { Events } = require("discord.js");
2+
3+
module.exports = {
4+
name: Events.GuildMemberRemove,
5+
once: false,
6+
execute(member) {
7+
/** @type {DBuser} */
8+
const userDB = global.userDB;
9+
10+
// Get report channel
11+
if (member.user.bot || member.user.system) return;
12+
13+
userDB.user_leave(member.id);
14+
},
15+
};

lib/database/database.js

+55-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DBuser {
9393
console.log("Running creating user table");
9494
await client.query("BEGIN");
9595
const query = `CREATE TABLE users (
96-
userid INTEGER PRIMARY KEY,
96+
userid TEXT PRIMARY KEY,
9797
joindate DATE NOT NULL,
9898
leavedate DATE,
9999
userleft BOOLEAN
@@ -196,7 +196,7 @@ class DBuser {
196196
try {
197197
await client.query("BEGIN");
198198
const values = [time, true, userid];
199-
const query = "UPDATE users SET leavedate = $1 , userleft = $2 where userid = $3";
199+
const query = "UPDATE users SET leavedate = $1 , userleft = $2 where userid = $3";
200200
await client.query(query, values);
201201

202202
await client.query("COMMIT");
@@ -215,6 +215,8 @@ class DBuser {
215215
time.setMilliseconds(0);
216216
time = time.toISOString();
217217

218+
let type = "new";
219+
218220
const client = await this.pool.connect();
219221
try {
220222
await client.query("BEGIN");
@@ -227,6 +229,9 @@ class DBuser {
227229
query = "UPDATE users SET joindate=$1, userleft=$2 where userid=$3";
228230
values = [time, false, userid];
229231
await client.query(query, values);
232+
233+
// Report rejoining user to channel
234+
type = "rejoin";
230235
} else {
231236
query =
232237
"INSERT INTO users (USERID, JOINDATE, LEAVEDATE, USERLEFT) VALUES ($1,$2,$3,$4)";
@@ -241,6 +246,40 @@ class DBuser {
241246
client.release();
242247
// console.log("Client released successfully.")
243248
}
249+
250+
return type;
251+
}
252+
253+
async get_user_info(userid) {
254+
const client = await this.pool.connect();
255+
let info = null;
256+
257+
try {
258+
await client.query("BEGIN");
259+
260+
const query = "select * from users where userid = $1";
261+
const values = [userid];
262+
const result = await client.query(query, values);
263+
264+
if (result.rows.length != 0) {
265+
const row = result.rows[0];
266+
267+
info = {
268+
userId: row["userid"],
269+
joinDate: row["joindate"],
270+
leaveDate: row["leavedate"],
271+
userLeft: row["userleft"],
272+
};
273+
}
274+
} catch (ex) {
275+
console.log(`An unexpected error occurred: ${ex}`);
276+
} finally {
277+
await client.query("ROLLBACK");
278+
client.release();
279+
// console.log("Client released successfully.")
280+
}
281+
282+
return info;
244283
}
245284

246285
// Adding a user role
@@ -477,6 +516,20 @@ class DBuser {
477516
client.release();
478517
}
479518
}
519+
520+
async deleteUsers() {
521+
// Temporary - delete after use
522+
const client = await this.pool.connect();
523+
try {
524+
// Query to delete users who have left the server
525+
const query = `DROP TABLE users CASCADE;`;
526+
await client.query(query);
527+
} catch (error) {
528+
console.error(error);
529+
} finally {
530+
client.release();
531+
}
532+
}
480533
}
481534

482535
module.exports = {

0 commit comments

Comments
 (0)