-
Notifications
You must be signed in to change notification settings - Fork 7
[DISC-110] Adding Course Chats 1-year "Subscription" #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2873c3d
Added database implementation of user roles when assigned and removed
ericwu2205 2e1886a
Added time checking function for expired user_roles and added time as…
ericwu2205 bd0a619
Added on ready file with cron.js to perform daily check of old_roles
ericwu2205 e7e0449
Adding new package cron for scheduling
ericwu2205 6dd6341
fixing lint issues
ericwu2205 1d06cd5
Fixing prettier issues
ericwu2205 39e2bef
Merge branch 'develop' into dev/autoroledelete
ericwu2205 6c98340
Package changes
ericwu2205 f3dc44d
Restoring develop package lock.json and fixing db_ready
ericwu2205 e83b0ca
Moving guild and roles out of for loop to remove redundant fetching
ericwu2205 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,45 @@ | ||
// @ts-check | ||
const { DBuser } = require("../lib/database/database"); | ||
const { CronJob } = require("cron"); | ||
|
||
const CSESOC_SERVER_ID = "693779865916276746"; | ||
// const TEST_SERVER_ID = "1220297696829509713"; | ||
|
||
module.exports = { | ||
name: "ready", | ||
once: true, | ||
async execute(client) { | ||
/** @type {DBuser} */ | ||
const userDB = new DBuser(); | ||
global.userDB = userDB; | ||
|
||
// Set up an automatic database check to see if there is any out of date roles. | ||
const role_job = new CronJob("0 0 12 * * *", async function () { | ||
console.log("Performing daily check of old roles at 12:00pm"); | ||
|
||
const old_roles = await userDB.checkTimeAssigned(); | ||
for (const removed_role of old_roles) { | ||
try { | ||
const guild = await client.guilds.fetch(CSESOC_SERVER_ID); | ||
const member = await guild.members.fetch(removed_role.userid); | ||
const roles = await guild.roles.fetch(); | ||
const role = roles.find((r) => r.name === removed_role.role_name); | ||
|
||
if (member && role) { | ||
await member.roles.remove(role); | ||
await userDB.remove_user_role(removed_role.userid, removed_role.role_name); | ||
// console.log(`Removed role ${removed_role.role_name} from user ${removed_role.userid}`); | ||
} else { | ||
console.log( | ||
`Could not find role ${removed_role.role_name} or user ${removed_role.userid}`, | ||
); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
}); | ||
|
||
role_job.start(); | ||
}, | ||
}; |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.