Skip to content
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

Auto Spoopy piece #295

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/cisc-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/spoopylogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/lib/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ export class CommandError extends Error {
}

}

export class SpookyError extends Error {

constructor(message: string) {
super(message);
this.name = 'Spoopification has taken place';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Petition to make this say
Boo! and Un-boo! when you spoopify and unspoopify respectively

this.stack = undefined;
}

}
36 changes: 36 additions & 0 deletions src/pieces/autoSpookyness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { GUILDS } from '@root/config';
import { Client } from 'discord.js';
import { schedule } from 'node-cron';
import { SpookyError } from '@lib/types/errors';

async function register(bot: Client): Promise<void> {
// Runs of the first of October at midnight
schedule('0 0 1 10 *', () => {
enableSpook(bot)
.catch(async error => bot.emit('error', error));
});

// Runs on the first of November at midnight
schedule('0 0 1 11 *', () => {
disableSpook(bot)
.catch(async error => bot.emit('error', error));
});
}

async function enableSpook(bot:Client) {
const guild = bot.guilds.cache.get(GUILDS.MAIN);

await guild.setIcon(`${__dirname}/../../../assets/images/spoopylogo.png`, 'Spoopifying the server.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is how they do it everywhere else but I still cry every time I see it


bot.emit('error', new SpookyError('Spoopified the server'));
}

async function disableSpook(bot:Client) {
const guild = bot.guilds.cache.get(GUILDS.MAIN);

await guild.setIcon(`${__dirname}/../../../assets/images/cisc-logo.png`, 'Spoopifying the server.');

bot.emit('error', new SpookyError('Un-spoopified the server'));
BenSegal855 marked this conversation as resolved.
Show resolved Hide resolved
}

export default register;
26 changes: 18 additions & 8 deletions src/sage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'module-alias/register';
import consoleStamp from 'console-stamp';
import { MongoClient } from 'mongodb';
import { ApplicationCommandPermissionData, Client, ExcludeEnum, Intents, PartialTypes, Team } from 'discord.js';
import { ApplicationCommandPermissionData, Client, ExcludeEnum, Intents, PartialTypes } from 'discord.js';
import { readdirRecursive } from '@root/src/lib/utils/generalUtils';
BenSegal855 marked this conversation as resolved.
Show resolved Hide resolved
import { DB, BOT, PREFIX, GITHUB_TOKEN } from '@root/config';
import { Octokit } from '@octokit/rest';
Expand Down Expand Up @@ -54,15 +54,25 @@ async function main() {

bot.once('ready', async () => {
// I'm mad about this - Josh </3
const team = (await bot.application.fetch()).owner as Team;
setBotmasterPerms(team.members.map(value => {
const permData: ApplicationCommandPermissionData = {
id: value.id,
// Don't worry Josh, I fix - Ben <3
const owners = (await bot.application.fetch()).owner; // as Team;
BenSegal855 marked this conversation as resolved.
Show resolved Hide resolved
if ('members' in owners) {
setBotmasterPerms(owners.members.map(value => {
const permData: ApplicationCommandPermissionData = {
id: value.id,
permission: true,
type: 'USER'
};
return permData;
}));
} else {
setBotmasterPerms([{
id: owners.id,
permission: true,
type: 'USER'
};
return permData;
}));
}]);
}


const pieceFiles = readdirRecursive(`${__dirname}/pieces`);
for (const file of pieceFiles) {
Expand Down