This commit is contained in:
Logan Cusano
2024-08-11 20:14:36 -04:00
parent 94374b4d45
commit cf49ac414a
6 changed files with 187 additions and 97 deletions

View File

@@ -2,20 +2,30 @@ import { DebugBuilder } from "../../modules/debugger.mjs";
const log = new DebugBuilder("server", "discordBot.addons.linkCop");
import { gptHandler } from "../modules/gptHandler.mjs";
import dotenv from "dotenv";
import { getGuildConfig, setGuildConfig } from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
import {
getGuildConfig,
setGuildConfig,
} from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
dotenv.config();
const linkRegExp = /http[s]?:\/\/\S+/g;
export const linkCop = async (nodeIo, message) => {
// Set the channel IDs based on the guild the message was sent in
const approvedLinksChannel = await getGuildConfig(message.guild.id, "approvedLinksChannel") || "767303243285790721";
const restrictedChannelIds = await getGuildConfig(message.guild.id, "restrictedChannelIds");
const approvedLinksChannel =
(await getGuildConfig(message.guild.id, "approvedLinksChannel")) ||
"767303243285790721";
const restrictedChannelIds = await getGuildConfig(
message.guild.id,
"restrictedChannelIds",
);
// Check if the message was sent in an restricted channel
if (
message.channel.id == approvedLinksChannel || !Array.isArray(restrictedChannelIds) ||
(Array.isArray(restrictedChannelIds) || !restrictedChannelIds.includes(message.channel.id))
message.channel.id == approvedLinksChannel ||
!Array.isArray(restrictedChannelIds) ||
Array.isArray(restrictedChannelIds) ||
!restrictedChannelIds.includes(message.channel.id)
) {
return false;
}

View File

@@ -4,12 +4,20 @@ import dotenv from "dotenv";
dotenv.config();
import { Events } from "discord.js";
import { gptHandler } from "../modules/gptHandler.mjs";
import { getGuildConfig, setGuildConfig, getConfig, setConfig } from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
import {
getGuildConfig,
setGuildConfig,
getConfig,
setConfig,
} from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
export const name = Events.GuildMemberAdd;
export async function execute(nodeIo, member) {
const welcomeChannel = await getGuildConfig(message.guild.id, "welcomeChannelId");
export async function execute(nodeIo, member) {
const welcomeChannel = await getGuildConfig(
message.guild.id,
"welcomeChannelId",
);
log.INFO("New user joined the server", member);
let conversation = [];
conversation.push({

View File

@@ -6,19 +6,33 @@ import { Events } from "discord.js";
import { gptInteraction } from "../addons/gptInteraction.mjs";
import { linkCop } from "../addons/linkCop.mjs";
import PresenceManager from "../modules/presenceManager.mjs";
import { getGuildConfig, setGuildConfig } from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
import {
getGuildConfig,
setGuildConfig,
} from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
export const name = Events.MessageCreate;
export async function execute(nodeIo, message) {
// Get the ignored channels from the server config
const IGNORED_CHANNELS = await getGuildConfig(message.guild.id, "ignoredChannels");
const IGNORED_CHANNELS = await getGuildConfig(
message.guild.id,
"ignoredChannels",
);
// Ignore ignored channels
if (!Array.isArray(IGNORED_CHANNELS) || Array.isArray(IGNORED_CHANNELS) && IGNORED_CHANNELS.includes(message.channel.id)) { return; }
if (
!Array.isArray(IGNORED_CHANNELS) ||
(Array.isArray(IGNORED_CHANNELS) &&
IGNORED_CHANNELS.includes(message.channel.id))
) {
return;
}
// Ignore messages from a bot
if (message.author.bot) { return; }
if (message.author.bot) {
return;
}
log.INFO("Message create", message);

View File

@@ -1,5 +1,8 @@
import { getConfig, setConfig } from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
import { ActivityType, PresenceUpdateStatus } from 'discord.js';
import {
getConfig,
setConfig,
} from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
import { ActivityType, PresenceUpdateStatus } from "discord.js";
class PresenceManager {
/**
@@ -41,20 +44,26 @@ class PresenceManager {
if (!defaultPresence) {
defaultPresence = {
status: 'idle',
activities: [{
name: 'your commands',
type: 'LISTENING'
}]
status: "idle",
activities: [
{
name: "your commands",
type: "LISTENING",
},
],
};
await setConfig('presence', defaultPresence);
await setConfig("presence", defaultPresence);
}
console.log("Default Presence:", defaultPresence);
// Update your bot's presence using this configuration
await this.setPresence(defaultPresence.status, defaultPresence.activities[0].type, defaultPresence.activities[0].name);
await this.setPresence(
defaultPresence.status,
defaultPresence.activities[0].type,
defaultPresence.activities[0].name,
);
}
/**
@@ -64,18 +73,18 @@ class PresenceManager {
*/
convertActivityType(activityType) {
switch (activityType.toUpperCase()) {
case 'PLAYING':
case "PLAYING":
return ActivityType.Playing;
case 'STREAMING':
case "STREAMING":
return ActivityType.Streaming;
case 'LISTENING':
case "LISTENING":
return ActivityType.Listening;
case 'WATCHING':
case "WATCHING":
return ActivityType.Watching;
case 'COMPETING':
case "COMPETING":
return ActivityType.Competing;
default:
throw new Error('Invalid activity type');
throw new Error("Invalid activity type");
}
}
@@ -86,19 +95,18 @@ class PresenceManager {
*/
convertStatus(status) {
switch (status.toLowerCase()) {
case 'online':
case "online":
return PresenceUpdateStatus.Online;
case 'idle':
case "idle":
return PresenceUpdateStatus.Idle;
case 'dnd':
case "dnd":
return PresenceUpdateStatus.DoNotDisturb;
case 'invisible':
case "invisible":
return PresenceUpdateStatus.Invisible;
default:
throw new Error('Invalid status');
throw new Error("Invalid status");
}
}
}
export default PresenceManager;