Skip to content

Commit

Permalink
move motd nickchange to motd file
Browse files Browse the repository at this point in the history
where it should've been in the first place
  • Loading branch information
Techbot121 authored and Meta Construct committed Dec 1, 2024
1 parent fbd0463 commit eb5ec6d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 67 deletions.
57 changes: 57 additions & 0 deletions app/services/Motd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,52 @@ type ImgurResponse = {
status: number;
};

const filter = [
"again",
"also",
"an",
"and",
"but",
"by",
"come",
"despite",
"did",
"do",
"done",
"else",
"for",
"has",
"hasn't",
"hasnt",
"have",
"i'm",
"if",
"im",
"in",
"instead",
"is",
"it's",
"it",
"its",
"like",
"literally",
"me",
"myself",
"nor",
"of",
"rather",
"so",
"than",
"then",
"there",
"this",
"to",
"was",
"while",
"with",
"yet",
];

export class Motd extends Service {
name = "Motd";
messages: string[] = [];
Expand Down Expand Up @@ -127,6 +173,7 @@ export class Motd extends Service {
},
}
);
await this.setMotdNickName(msg);
}

private async executeImageJob(patch?: boolean, msgId?: string): Promise<void> {
Expand Down Expand Up @@ -221,6 +268,16 @@ export class Motd extends Service {
}
} catch {}
}

async setMotdNickName(motd: string): Promise<boolean | undefined> {
let nick = "Meta";
const wordList = motd
.split(" ")
.filter(w => w.length <= 22 && !filter.includes(w.toLowerCase()));
const word = wordList[(Math.random() * wordList?.length) | 0];
nick = word.charAt(0).toUpperCase() + word.slice(1);
return await this.container.getService("DiscordBot")?.setNickname(nick, "Random Motd name");
}
}
export default (container: Container): Service => {
return new Motd(container);
Expand Down
72 changes: 5 additions & 67 deletions app/services/discord/modules/discord-guild-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,6 @@ const fileExists = async (filePath: PathLike) =>
.then(stats => stats.isFile())
.catch(() => false);

const filter = [
"again",
"also",
"an",
"and",
"but",
"by",
"come",
"despite",
"did",
"do",
"done",
"else",
"for",
"has",
"hasn't",
"hasnt",
"have",
"i'm",
"if",
"im",
"in",
"instead",
"is",
"it's",
"it",
"its",
"like",
"literally",
"me",
"myself",
"nor",
"of",
"rather",
"so",
"than",
"then",
"there",
"this",
"to",
"was",
"while",
"with",
"yet",
];

export default (bot: DiscordBot): void => {
const data = bot.container.getService("Data");
if (!data) return;
Expand All @@ -98,20 +52,11 @@ export default (bot: DiscordBot): void => {
const guild = bot.getGuild();
if (!guild) return;

const changeIcon = async (filePath: string, eventName: string, nickName: string) => {
const changeIcon = async (filePath: string, eventName: string) => {
const eventChange = data.lastDiscordGuildEvent !== eventName;
const nickChange = guild.members.me?.nickname !== nickName;
const guildEvents = await guild.scheduledEvents.fetch();
if (!eventChange && !nickChange) return;
if (!eventChange) return;

if (nickChange) {
try {
await bot.setNickname(nickName, "Random Motd name");
} catch (err) {
console.error(err);
}
data.lastDiscordNickName = nickName;
}
if (eventChange && !guildEvents.find(ev => ev.isActive())) {
try {
await guild.setIcon(
Expand All @@ -134,7 +79,6 @@ export default (bot: DiscordBot): void => {
const checkDate = async () => {
let filePath = defaultIconPath;
let eventName = "None";
let nick = "Meta";

for (const { icon, range } of events) {
const [start, end] = range;
Expand Down Expand Up @@ -169,18 +113,12 @@ export default (bot: DiscordBot): void => {
}
}

const wordList = data.lastMotd
.split(" ")
.filter(w => w.length <= 22 && !filter.includes(w.toLowerCase()));
const word = wordList[(Math.random() * wordList?.length) | 0];
nick = word.charAt(0).toUpperCase() + word.slice(1);

return { filePath: filePath, eventName, nickName: nick };
return { filePath: filePath, eventName };
};

const doIt = async () => {
const { filePath, eventName, nickName } = await checkDate();
changeIcon(filePath, eventName, nickName);
const { filePath, eventName } = await checkDate();
changeIcon(filePath, eventName);
};

scheduleJob("0 0 * * *", doIt);
Expand Down

0 comments on commit eb5ec6d

Please sign in to comment.