Skip to content

Commit

Permalink
Merge pull request #9 from PretendoNetwork/network-dumps
Browse files Browse the repository at this point in the history
Scan and reupload network dumps
  • Loading branch information
jonbarrow committed Jan 11, 2024
2 parents 3b2c7df + cca0b00 commit 56e9a8b
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 918 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ typings/
# custom
config.json
db.json
database.db
database.db
network-dumps-tmp
982 changes: 98 additions & 884 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"@discordjs/builders": "^1.3.0",
"@discordjs/rest": "^1.3.0",
"@napi-rs/canvas": "^0.1.40",
"axios": "^1.4.0",
"cld": "^2.9.0",
"discord-api-types": "^0.31.2",
"discord-html-transcripts": "^3.1.2",
"discord.js": "^14.8.0",
"fs-extra": "^10.1.0",
"lookpath": "^1.2.2",
"natural": "^6.5.0",
"sqlite": "^4.1.2",
"sqlite3": "^5.1.2"
Expand Down
4 changes: 4 additions & 0 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ const config = require('../config.json');

const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.MessageContent,
],
partials: [
Discord.Partials.Channel
]
});

Expand Down
4 changes: 3 additions & 1 deletion src/commands/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const { SlashCommandBuilder } = require('@discordjs/builders');
const editableOptions = [
'admin_role_id',
'unverified_role_id',
'developer_role_id',
'mod_applications_channel_id',
'reports_channel_id',
'readme_channel_id',
'rules_channel_id',
'stats_members_channel_id',
'stats_people_channel_id',
'stats_bots_channel_id',
'uploaded_network_dumps_channel_id',
];

async function verifyInputtedKey(interaction) {
Expand Down Expand Up @@ -40,7 +42,7 @@ async function settingsHandler(interaction) {
'```\n' + key + '=' + '\'' + `${value}` + '\'' + '\n```',
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
parse: [], // * Dont allow tagging anything
},
});
return;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/togglerole.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function toggleroleHandler(interaction) {
}

const hasRole = member.roles.cache.has(role.id);

if (hasRole) {
await member.roles.remove(role);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ async function connect() {
guild_id TEXT,
admin_role_id TEXT,
unverified_role_id TEXT,
developer_role_id TEXT,
mod_applications_channel_id TEXT,
reports_channel_id TEXT,
readme_channel_id TEXT,
rules_channel_id TEXT,
stats_members_channel_id TEXT,
stats_people_channel_id TEXT,
stats_bots_channel_id TEXT,
uploaded_network_dumps_channel_id TEXT,
UNIQUE(guild_id)
)`);

Expand Down
51 changes: 26 additions & 25 deletions src/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const timers = require('node:timers/promises');
const Discord = require('discord.js');
const { button: disableNLPButton } = require('../buttons/disable-nlp');
const { button: expandErrorButton } = require('../buttons/expand-error');
const errorCodeUtils = require('../utils/errorCode');
const { networkDumpsUploader } = require('../utils/network-dumps-upload');
const database = require('../database');

const ayyRegex = /\bay{1,}\b/gi;
Expand All @@ -16,36 +16,37 @@ async function messageCreateHandler(message) {
return;
}

// * ayy => lmaoo
if (ayyRegex.test(message.content)) {
const lmaod = message.content.replaceAll(ayyRegex, (match) => {
let newMatch = match.replaceAll('y', 'o').replaceAll('Y', 'O');
newMatch = newMatch.replaceAll('a', 'lma').replaceAll('A', 'LMA');
return newMatch;
});

// Check that the message isn't too long to be sent
if (lmaod.length < 2000) {
await message.reply({
content: lmaod,
allowedMentions: { parse: [] }
// * Message was sent in the guild
if (!(message.channel instanceof Discord.DMChannel)) {
// * ayy => lmaoo
if (ayyRegex.test(message.content)) {
const lmaod = message.content.replaceAll(ayyRegex, (match) => {
let newMatch = match.replaceAll('y', 'o').replaceAll('Y', 'O');
newMatch = newMatch.replaceAll('a', 'lma').replaceAll('A', 'LMA');
return newMatch;
});
} else {
await message.reply('Looks like the resulting message is too long :/');

// * Check that the message isn't too long to be sent
if (lmaod.length < 2000) {
await message.reply({
content: lmaod,
allowedMentions: { parse: [] }
});
} else {
await message.reply('Looks like the resulting message is too long :/');
}
}

return;
}
// * Check if automatic help is disabled
const isHelpDisabled = await database.checkAutomaticHelpDisabled(message.guildId, message.member.id);

// * Check if automatic help is disabled
const isHelpDisabled = await database.checkAutomaticHelpDisabled(message.guildId, message.member.id);
if (!isHelpDisabled) {
// * Only do automatic help if not disabled
await tryAutomaticHelp(message);
}

if (isHelpDisabled) {
// * Bail if automatic help is disabled
return;
await networkDumpsUploader(message);
}

await tryAutomaticHelp(message);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/nlp/message-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const trainingDataDir = `${__dirname}/training-data`;

class AIMessageProcessor {
constructor() {
this.classifierThreshold = 0.8;
this.cldThreshold = 80;
this.classifierThreshold = 1;
this.cldThreshold = 100;
this.classifiers = {};
this.answers = {};

Expand Down
6 changes: 3 additions & 3 deletions src/utils/cooldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ function getRelativeTime(timestamp) {
}

else if (elapsed < msPerMonth) {
return `in ${Math.round(elapsed/msPerDay)} day(s)`;
return `in ${Math.round(elapsed/msPerDay)} day(s)`;
}

else if (elapsed < msPerYear) {
return `in ${Math.round(elapsed/msPerMonth)} month(s)`;
return `in ${Math.round(elapsed/msPerMonth)} month(s)`;
}

else {
return `in ${Math.round(elapsed/msPerYear)} year(s)`;
return `in ${Math.round(elapsed/msPerYear)} year(s)`;
}
}

Expand Down
Loading

0 comments on commit 56e9a8b

Please sign in to comment.