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 all 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.
52 changes: 52 additions & 0 deletions src/pieces/autoSpookyness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { CHANNELS, GUILDS } from '@root/config';
import { Client, MessageEmbed, TextChannel } from 'discord.js';
import { schedule } from 'node-cron';

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);
const serverLog = guild.channels.fetch(CHANNELS.SERVER_LOG) as Promise<TextChannel>;

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


(await serverLog).send({
embeds: [
new MessageEmbed()
.setColor('DARK_ORANGE')
.setTitle('Spoopification has taken place')
.setThumbnail(guild.iconURL())
]
})
}

async function disableSpook(bot:Client) {
const guild = bot.guilds.cache.get(GUILDS.MAIN);
const serverLog = guild.channels.fetch(CHANNELS.SERVER_LOG) as Promise<TextChannel>;


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

(await serverLog).send({
embeds: [
new MessageEmbed()
.setColor('DARK_ORANGE')
.setTitle('Spoopification has been removed')
.setThumbnail(guild.iconURL())
]
})
}

export default register;
28 changes: 19 additions & 9 deletions src/sage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'module-alias/register';
import consoleStamp from 'console-stamp';
import { MongoClient } from 'mongodb';
import { ApplicationCommandPermissionData, Client, ExcludeEnum, Intents, PartialTypes, Team } from 'discord.js';
import { readdirRecursive } from '@root/src/lib/utils/generalUtils';
import { ApplicationCommandPermissionData, Client, ExcludeEnum, Intents, PartialTypes } from 'discord.js';
import { readdirRecursive } from '@lib/utils/generalUtils';
import { DB, BOT, PREFIX, GITHUB_TOKEN } from '@root/config';
import { Octokit } from '@octokit/rest';
import { version as sageVersion } from '@root/package.json';
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;
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