mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-18 00:31:00 -05:00
Compare commits
7 Commits
42e172c502
...
341a8e1156
Author | SHA1 | Date | |
---|---|---|---|
|
341a8e1156 | ||
|
b2d2300d13 | ||
|
a862564248 | ||
|
a5e45a3b13 | ||
|
ab9e88c263 | ||
|
1d02e781dc | ||
|
d6812cb6d3 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,4 +4,5 @@ ips.txt
|
|||||||
.yarn
|
.yarn
|
||||||
# TypeScript stuff
|
# TypeScript stuff
|
||||||
dist
|
dist
|
||||||
|
src/private
|
||||||
src/*.json
|
src/*.json
|
||||||
|
@ -32,11 +32,10 @@
|
|||||||
"engineStrict": true,
|
"engineStrict": true,
|
||||||
"packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb",
|
"packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/auth-token": "4.0.0",
|
"@napi-rs/canvas": "0.1.45",
|
||||||
"@octokit/rest": "20.0.2",
|
"@octokit/rest": "20.0.2",
|
||||||
"@toast/tokenservice-client": "1.0.11",
|
"@toast/tokenservice-client": "1.0.11",
|
||||||
"ansi-colors": "4.1.3",
|
"ansi-colors": "4.1.3",
|
||||||
"canvas": "2.11.2",
|
|
||||||
"dayjs": "1.11.10",
|
"dayjs": "1.11.10",
|
||||||
"discord.js": "14.14.1",
|
"discord.js": "14.14.1",
|
||||||
"fast-xml-parser": "4.3.4",
|
"fast-xml-parser": "4.3.4",
|
||||||
@ -45,7 +44,7 @@
|
|||||||
"pg": "8.11.3",
|
"pg": "8.11.3",
|
||||||
"pg-hstore": "2.3.4",
|
"pg-hstore": "2.3.4",
|
||||||
"redis": "4.6.12",
|
"redis": "4.6.12",
|
||||||
"sequelize": "6.35.2",
|
"sequelize": "6.36.0",
|
||||||
"simple-git": "3.22.0",
|
"simple-git": "3.22.0",
|
||||||
"systeminformation": "5.21.24",
|
"systeminformation": "5.21.24",
|
||||||
"undici": "6.6.0"
|
"undici": "6.6.0"
|
||||||
|
@ -6,7 +6,7 @@ import Formatters from '../helpers/Formatters.js';
|
|||||||
import GitHub from '../helpers/GitHub.js';
|
import GitHub from '../helpers/GitHub.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import util from 'node:util';
|
import util from 'node:util';
|
||||||
import fs, { writeFileSync } from 'node:fs';
|
import fs from 'node:fs';
|
||||||
export default class Developer {
|
export default class Developer {
|
||||||
static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
|
static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
|
||||||
if (!client.config.whitelist.includes(interaction.user.id)) return MessageTool.youNeedRole(interaction, 'bottech');
|
if (!client.config.whitelist.includes(interaction.user.id)) return MessageTool.youNeedRole(interaction, 'bottech');
|
||||||
@ -71,13 +71,19 @@ export default class Developer {
|
|||||||
`╰ Deletions: **${commitStats.deletion}**`,
|
`╰ Deletions: **${commitStats.deletion}**`,
|
||||||
`╰ Total: **${commitStats.total}**`
|
`╰ Total: **${commitStats.total}**`
|
||||||
);
|
);
|
||||||
|
if (interaction.options.getBoolean('private_dir')) {
|
||||||
|
const priv_file = await GitHub.PrivateRepository();
|
||||||
|
fs.writeFileSync('src/private/_.ts', Buffer.from(priv_file.content, 'base64').toString('utf8'));
|
||||||
|
const update_success = `Updated the private file with latest data from the repository. (\`${priv_file.sha.slice(0, 7)}\`)`;
|
||||||
|
if (interaction.replied) interaction.followUp(update_success);
|
||||||
|
else interaction.reply(update_success);
|
||||||
|
};
|
||||||
exec('git pull', {windowsHide:true}, (err:Error, stdout)=>{
|
exec('git pull', {windowsHide:true}, (err:Error, stdout)=>{
|
||||||
if (err) hammondYouIdiot.edit(`\`\`\`${UsernameHelper(err.message)}\`\`\``);
|
if (err) hammondYouIdiot.edit(`\`\`\`${UsernameHelper(err.message)}\`\`\``);
|
||||||
else if (stdout.includes('Already up to date')) hammondYouIdiot.edit('Repository is currently up to date.');
|
else if (stdout.includes('Already up to date')) hammondYouIdiot.edit('Repository is currently up to date.');
|
||||||
else hammondYouIdiot.edit('Running `yarn tsc`...').then(()=>exec('yarn tsc', {windowsHide:true}, (err:Error)=>{
|
else hammondYouIdiot.edit('Running `yarn tsc`...').then(()=>exec('yarn tsc', {windowsHide:true}, (err:Error)=>{
|
||||||
if (err) hammondYouIdiot.edit(`\`\`\`${UsernameHelper(err.message)}\`\`\``);
|
if (err) hammondYouIdiot.edit(`\`\`\`${UsernameHelper(err.message)}\`\`\``);
|
||||||
else if (interaction.options.getBoolean('restart')) hammondYouIdiot.edit(msgBody + `\nUptime: **${Formatters.timeFormat(process.uptime()*1000, 4, {longNames:true, commas:true})}**`).then(()=>process.exit(0));
|
else hammondYouIdiot.edit(msgBody + `\nUptime: **${Formatters.timeFormat(process.uptime()*1000, 4, {longNames:true, commas:true})}**`).then(()=>process.exit(0));
|
||||||
else hammondYouIdiot.edit(msgBody);
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -102,7 +108,7 @@ export default class Developer {
|
|||||||
if (name) currentActivities[0].name = name;
|
if (name) currentActivities[0].name = name;
|
||||||
if (url) currentActivities[0].url = url;
|
if (url) currentActivities[0].url = url;
|
||||||
client.user.setPresence(client.config.botPresence);
|
client.user.setPresence(client.config.botPresence);
|
||||||
writeFileSync(process.argv[2] ?? 'src/config.json', JSON.stringify(client.config, null, 2));
|
fs.writeFileSync(process.argv[2] ?? 'src/config.json', JSON.stringify(client.config, null, 2));
|
||||||
interaction.reply(MessageTool.concatMessage(
|
interaction.reply(MessageTool.concatMessage(
|
||||||
'Presence updated:',
|
'Presence updated:',
|
||||||
`Status: **${client.config.botPresence.status}**`,
|
`Status: **${client.config.botPresence.status}**`,
|
||||||
@ -125,6 +131,7 @@ export default class Developer {
|
|||||||
client.users.cache.get(member.id).send(`${message}\n╰ ${interaction.member.displayName}`).then(()=>int.edit(`Successfully sent a DM to **${member.user.username}** with the following message:\n\`\`\`${message}\`\`\``)).catch((e:Error)=>int.edit(`\`${e.message}\``))
|
client.users.cache.get(member.id).send(`${message}\n╰ ${interaction.member.displayName}`).then(()=>int.edit(`Successfully sent a DM to **${member.user.username}** with the following message:\n\`\`\`${message}\`\`\``)).catch((e:Error)=>int.edit(`\`${e.message}\``))
|
||||||
},
|
},
|
||||||
modify_rank_msgs: async()=>{
|
modify_rank_msgs: async()=>{
|
||||||
|
if (interaction.guildId !== client.config.dcServer.id) return interaction.reply({content: 'This command is only available in the main server.', ephemeral: true});
|
||||||
const member = interaction.options.getMember('member');
|
const member = interaction.options.getMember('member');
|
||||||
const messages = interaction.options.getInteger('new-message-count');
|
const messages = interaction.options.getInteger('new-message-count');
|
||||||
const oldData = await client.userLevels.fetchUser(member.id);
|
const oldData = await client.userLevels.fetchUser(member.id);
|
||||||
@ -135,7 +142,6 @@ export default class Developer {
|
|||||||
`Successfully modified the message count of **${member.displayName}**`,
|
`Successfully modified the message count of **${member.displayName}**`,
|
||||||
`╰ Old: **${oldData.dataValues.messages.toLocaleString('en-US')}**`,
|
`╰ Old: **${oldData.dataValues.messages.toLocaleString('en-US')}**`,
|
||||||
`╰ New: **${newData.messages.toLocaleString('en-US')}**`,
|
`╰ New: **${newData.messages.toLocaleString('en-US')}**`,
|
||||||
`╰ Difference: **${(newData.messages - oldData.dataValues.messages).toLocaleString('en-US')}**`,
|
|
||||||
'Although if you set the number too high or low, it will have a bigger impact on the leaderboard graph.'
|
'Although if you set the number too high or low, it will have a bigger impact on the leaderboard graph.'
|
||||||
))
|
))
|
||||||
]})
|
]})
|
||||||
@ -163,8 +169,8 @@ export default class Developer {
|
|||||||
.setName('update')
|
.setName('update')
|
||||||
.setDescription('Pull from repository and restart')
|
.setDescription('Pull from repository and restart')
|
||||||
.addBooleanOption(x=>x
|
.addBooleanOption(x=>x
|
||||||
.setName('restart')
|
.setName('private_dir')
|
||||||
.setDescription('Restart the bot after pulling from repository')
|
.setDescription('Update private directory from a repository too?')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
))
|
))
|
||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
|
@ -62,7 +62,7 @@ export default class MP {
|
|||||||
.setImage(`attachment://${attachmentName}`)
|
.setImage(`attachment://${attachmentName}`)
|
||||||
.setAuthor({name: `${DSS.slots.used}/${DSS.slots.capacity}`})
|
.setAuthor({name: `${DSS.slots.used}/${DSS.slots.capacity}`})
|
||||||
.setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`})
|
.setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`})
|
||||||
], files: [new client.attachment(canvas.toBuffer(), {name: attachmentName})]})
|
], files: [new client.attachment(canvas.toBuffer('image/jpeg'), {name: attachmentName})]})
|
||||||
},
|
},
|
||||||
details: async()=>{
|
details: async()=>{
|
||||||
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
||||||
|
@ -42,7 +42,7 @@ export default class Rank {
|
|||||||
name: 'Top users sorted by messages sent:',
|
name: 'Top users sorted by messages sent:',
|
||||||
value: allData.sort((a,b)=>b.messages - a.messages).slice(0,15).map((x,i)=>`${i+1}. <@${x.dataValues.id}>: ${x.messages.toLocaleString('en-US')}`).join('\n')
|
value: allData.sort((a,b)=>b.messages - a.messages).slice(0,15).map((x,i)=>`${i+1}. <@${x.dataValues.id}>: ${x.messages.toLocaleString('en-US')}`).join('\n')
|
||||||
}).setImage('attachment://dailyMessages.jpg').setFooter({text: 'Graph updates daily'})],
|
}).setImage('attachment://dailyMessages.jpg').setFooter({text: 'Graph updates daily'})],
|
||||||
files: [new client.attachment(graph.toBuffer(), {name: 'dailyMessages.jpg'})]
|
files: [new client.attachment(graph.toBuffer('image/jpeg'), {name: 'dailyMessages.jpg'})]
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
notification: async()=>{
|
notification: async()=>{
|
||||||
|
@ -4,7 +4,7 @@ import Logger from '../helpers/Logger.js';
|
|||||||
export default class Automoderator {
|
export default class Automoderator {
|
||||||
private static lockQuery:Set<Discord.Snowflake> = new Set();
|
private static lockQuery:Set<Discord.Snowflake> = new Set();
|
||||||
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
|
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
|
||||||
static async repeatedMessages(client:TClient, message:Discord.Message, action:'mute'|'ban', thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
|
static async repeatedMessages(client:TClient, message:Discord.Message, action:'mute'|'ban'|'softban', thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: type, count:1, firstTime:now, timeout: null};
|
if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: type, count:1, firstTime:now, timeout: null};
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
import {createCanvas, Canvas, CanvasRenderingContext2D} from 'canvas';
|
import {createCanvas, Canvas, SKRSContext2D} from '@napi-rs/canvas';
|
||||||
import {Config} from 'src/interfaces';
|
import {Config} from 'src/interfaces';
|
||||||
import ConfigHelper from '../helpers/ConfigHelper.js';
|
import ConfigHelper from '../helpers/ConfigHelper.js';
|
||||||
export default class CanvasBuilder {
|
export default class CanvasBuilder {
|
||||||
private canvas: Canvas;
|
private readonly canvas: Canvas;
|
||||||
private ctx: CanvasRenderingContext2D;
|
private readonly ctx: SKRSContext2D;
|
||||||
private config: Config;
|
private readonly config: Config;
|
||||||
|
private readonly palette = {
|
||||||
|
// Color palette for the graph -- The variables are named exactly what it shows in graph to make it easier to be referenced to.
|
||||||
|
oddHorizontal: '#555B63',
|
||||||
|
evenHorizontal: '#3E4245',
|
||||||
|
background: '#111111',
|
||||||
|
textColor: '#FFFFFF',
|
||||||
|
redLine: '#E62C3B',
|
||||||
|
yellowLine: '#FFEA00',
|
||||||
|
greenLine: '#57F287'
|
||||||
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.canvas = createCanvas(1500, 750);
|
this.canvas = createCanvas(1500, 750);
|
||||||
@ -13,20 +23,11 @@ export default class CanvasBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async generateGraph(data:number[], type:'players'|'leaderboard'):Promise<Canvas> {
|
public async generateGraph(data:number[], type:'players'|'leaderboard'):Promise<Canvas> {
|
||||||
// Color layout for the graph -- The variables are named exactly what it shows in graph to make it easier to be referenced to.
|
|
||||||
let oddHorizontal = '#555B63';
|
|
||||||
let evenHorizontal = '#3E4245';
|
|
||||||
let background = '#111111';
|
|
||||||
let textColor = '#FFFFFF';
|
|
||||||
let redLine = '#E62C3B';
|
|
||||||
let yellowLine = '#FFEA00';
|
|
||||||
let greenLine = '#57F287';
|
|
||||||
|
|
||||||
// Handle negative
|
// Handle negative
|
||||||
for (const [i, change] of data.entries()) if (change as number < 0) data[i] = data[i - 1] || data[i + 1] || 0;
|
for (const [i, change] of data.entries()) if (change < 0) data[i] = data[i - 1] || data[i + 1] || 0;
|
||||||
|
|
||||||
const LBdataFirst = Math.ceil(Math.max(...data) * 10 ** (-Math.max(...data).toString().split('').length + 1)) * 10 ** (Math.max(...data).toString().split('').length - 1)
|
const LBdataFirst = Math.ceil(Math.max(...data) * 10 ** (-Math.max(...data).toString().split('').length + 2)) * 10 ** (Math.max(...data).toString().split('').length - 2)
|
||||||
const LBdataSecond = Math.ceil(Math.max(...data) * 10 ** (-Math.max(...data).toString().split('').length + 2)) * 10 ** (Math.max(...data).toString().split('').length - 2)
|
const LBdataSecond = Math.ceil(Math.max(...data) * 10 ** (-Math.max(...data).toString().split('').length + 3)) * 10 ** (Math.max(...data).toString().split('').length - 3)
|
||||||
|
|
||||||
const firstTop = type === 'leaderboard' ? LBdataFirst : 16;
|
const firstTop = type === 'leaderboard' ? LBdataFirst : 16;
|
||||||
const secondTop = type === 'leaderboard' ? LBdataSecond : 16;
|
const secondTop = type === 'leaderboard' ? LBdataSecond : 16;
|
||||||
@ -34,7 +35,7 @@ export default class CanvasBuilder {
|
|||||||
const origin = [15, 65];
|
const origin = [15, 65];
|
||||||
const size = [1300, 630];
|
const size = [1300, 630];
|
||||||
const nodeWidth = size[0] / (data.length - 1);
|
const nodeWidth = size[0] / (data.length - 1);
|
||||||
this.ctx.fillStyle = background;
|
this.ctx.fillStyle = this.palette.background;
|
||||||
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
// Grey horizontal lines
|
// Grey horizontal lines
|
||||||
@ -47,33 +48,20 @@ export default class CanvasBuilder {
|
|||||||
}
|
}
|
||||||
const chosenInterval = intervalCandidates.sort((a,b)=>b[2]-a[2])[0];
|
const chosenInterval = intervalCandidates.sort((a,b)=>b[2]-a[2])[0];
|
||||||
let prevY:number[] = [];
|
let prevY:number[] = [];
|
||||||
this.ctx.strokeStyle = oddHorizontal;
|
this.ctx.strokeStyle = this.palette.oddHorizontal;
|
||||||
|
|
||||||
if (type === 'leaderboard') for (let i = 0; i <= chosenInterval[1]; i++) {
|
for (let i = 0; i <= chosenInterval[1]; i++) {
|
||||||
const y = origin[1] + size[1] - (i * (chosenInterval[0] / secondTop) * size[1]);
|
const y = origin[1] + size[1] - (i * (chosenInterval[0] / secondTop) * size[1]);
|
||||||
if (y < origin[1]) continue;
|
if (y < origin[1]) continue;
|
||||||
const even = ((i + 1) % 2) === 0;
|
const even = ((i + 1) % 2) === 0;
|
||||||
if (even) this.ctx.strokeStyle = evenHorizontal;
|
if (even) this.ctx.strokeStyle = this.palette.evenHorizontal;
|
||||||
this.ctx.beginPath();
|
this.ctx.beginPath();
|
||||||
this.ctx.lineTo(origin[0], y);
|
this.ctx.lineTo(origin[0], y);
|
||||||
this.ctx.lineTo(origin[0] + size[0], y);
|
this.ctx.lineTo(origin[0] + size[0], y);
|
||||||
this.ctx.stroke();
|
this.ctx.stroke();
|
||||||
this.ctx.closePath();
|
this.ctx.closePath();
|
||||||
if (even) this.ctx.strokeStyle = oddHorizontal;
|
if (even) this.ctx.strokeStyle = this.palette.oddHorizontal;
|
||||||
prevY = [y, i * chosenInterval[0]];
|
prevY.push(y, i * chosenInterval[0]); // It didn't seem to take effect when I tested on leaderboard, so using push instead for both players and leaderboard.
|
||||||
}
|
|
||||||
else for (let i = 0; i < data.length; i++) {
|
|
||||||
const y = origin[1] + size[1] - (i * (chosenInterval[0] / secondTop) * size[1]);
|
|
||||||
if (y < origin[1]) continue;
|
|
||||||
const even = ((i + 1) % 2) === 0;
|
|
||||||
if (even) this.ctx.strokeStyle = evenHorizontal;
|
|
||||||
this.ctx.beginPath();
|
|
||||||
this.ctx.lineTo(origin[0], y);
|
|
||||||
this.ctx.lineTo(origin[0] + size[0], y);
|
|
||||||
this.ctx.stroke();
|
|
||||||
this.ctx.closePath();
|
|
||||||
if (even) this.ctx.strokeStyle = oddHorizontal;
|
|
||||||
prevY.push(y, i * chosenInterval[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 30 day/minute mark
|
// 30 day/minute mark
|
||||||
@ -87,15 +75,14 @@ export default class CanvasBuilder {
|
|||||||
this.ctx.setLineDash([]);
|
this.ctx.setLineDash([]);
|
||||||
|
|
||||||
// Draw points
|
// Draw points
|
||||||
const isLeaderboard =()=>type === 'leaderboard' ? this.config.embedColor as string : null;
|
this.ctx.strokeStyle = type === 'leaderboard' ? this.config.embedColor as string : null;
|
||||||
this.ctx.strokeStyle = isLeaderboard();
|
this.ctx.fillStyle = type === 'leaderboard' ? this.config.embedColor as string : null;
|
||||||
this.ctx.fillStyle = isLeaderboard();
|
|
||||||
this.ctx.lineWidth = 5;
|
this.ctx.lineWidth = 5;
|
||||||
|
|
||||||
const gradient = this.ctx.createLinearGradient(0, origin[1], 0, origin[1] + size[1]);
|
const gradient = this.ctx.createLinearGradient(0, origin[1], 0, origin[1] + size[1]);
|
||||||
gradient.addColorStop(1 / 16, redLine);
|
gradient.addColorStop(1 / 16, this.palette.redLine);
|
||||||
gradient.addColorStop(5 / 16, yellowLine);
|
gradient.addColorStop(5 / 16, this.palette.yellowLine);
|
||||||
gradient.addColorStop(12 / 16, greenLine);
|
gradient.addColorStop(12 / 16, this.palette.greenLine);
|
||||||
|
|
||||||
let lastCoordinates:number[] = [];
|
let lastCoordinates:number[] = [];
|
||||||
for (let [i, currentValue] of data.entries()) {
|
for (let [i, currentValue] of data.entries()) {
|
||||||
@ -132,8 +119,8 @@ export default class CanvasBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
this.ctx.font = '400 ' + textSize + 'px sans-serif';
|
this.ctx.font = `400 ${textSize}px Ubuntu`;
|
||||||
this.ctx.fillStyle = textColor;
|
this.ctx.fillStyle = this.palette.textColor;
|
||||||
|
|
||||||
// Highest value
|
// Highest value
|
||||||
this.ctx.fillText(type === 'leaderboard'
|
this.ctx.fillText(type === 'leaderboard'
|
||||||
|
@ -5,6 +5,7 @@ import CmdTrigger from '../modules/CmdModule.js';
|
|||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
import ConfigHelper from '../helpers/ConfigHelper.js';
|
import ConfigHelper from '../helpers/ConfigHelper.js';
|
||||||
import Automoderator from '../components/Automod.js';
|
import Automoderator from '../components/Automod.js';
|
||||||
|
import __PRIVATE from '../private/_.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
export default class MessageCreate {
|
export default class MessageCreate {
|
||||||
static async run(client:TClient, message:Discord.Message) {
|
static async run(client:TClient, message:Discord.Message) {
|
||||||
@ -15,12 +16,21 @@ export default class MessageCreate {
|
|||||||
if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id) {
|
if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id) {
|
||||||
const automodFailReason = 'msg got possibly deleted by another bot.';
|
const automodFailReason = 'msg got possibly deleted by another bot.';
|
||||||
const automodRules = {
|
const automodRules = {
|
||||||
|
phishingDetection: {
|
||||||
|
check: async()=>await __PRIVATE.phishingDetection(message),
|
||||||
|
action: async()=>{
|
||||||
|
automodded = true;
|
||||||
|
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PHISHING', automodFailReason));
|
||||||
|
message.channel.send('Phishing links aren\'t allowed here. Nice try though!').then(msg=>setTimeout(()=>msg.delete(), 15000));
|
||||||
|
await Automoderator.repeatedMessages(client, message, 'softban', 60000, 2, 'phish', null, 'Phishing/scam link');
|
||||||
|
}
|
||||||
|
},
|
||||||
prohibitedWords: {
|
prohibitedWords: {
|
||||||
check: async()=>await client.prohibitedWords.findWord(Automoderator.scanMsg(message)),
|
check: async()=>await client.prohibitedWords.findWord(Automoderator.scanMsg(message)),
|
||||||
action: async()=>{
|
action: async()=>{
|
||||||
automodded = true;
|
automodded = true;
|
||||||
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
|
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
|
||||||
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000));
|
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 15000));
|
||||||
await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam');
|
await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
|
interface IDataContent {
|
||||||
|
sha: string;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
import {Octokit} from '@octokit/rest';
|
import {Octokit} from '@octokit/rest';
|
||||||
import {createTokenAuth} from '@octokit/auth-token';
|
|
||||||
import TSClient from './TSClient.js';
|
import TSClient from './TSClient.js';
|
||||||
import git from 'simple-git';
|
import git from 'simple-git';
|
||||||
const summonAuth = createTokenAuth((await TSClient()).octokit);
|
|
||||||
const octokit = new Octokit({auth: await summonAuth().token, timeZone: 'Australia/NSW', userAgent: 'Daggerbot-TS'});
|
const octokit = new Octokit({auth: (await TSClient()).octokit, timeZone: 'Australia/NSW', userAgent: 'Daggerbot-TS'});
|
||||||
export default class GitHub {
|
export default class GitHub {
|
||||||
private static repositoryConfig = {owner: 'toast-ts', repo: 'Daggerbot-TS', ref: 'HEAD'};
|
private static repositoryConfig = {owner: 'toast-ts', ref: 'HEAD'};
|
||||||
public static async RemoteRepository() {
|
public static async RemoteRepository() {
|
||||||
const {data} = await octokit.repos.getCommit(this.repositoryConfig);
|
const {data} = await octokit.repos.getCommit({repo: 'Daggerbot-TS', ...this.repositoryConfig});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
public static async LocalRepository() {
|
public static async LocalRepository() {
|
||||||
const {latest} = await git().log({maxCount: 1});
|
const {latest} = await git().log({maxCount: 1});
|
||||||
return latest;
|
return latest;
|
||||||
}
|
}
|
||||||
|
public static async PrivateRepository() {
|
||||||
|
const {data} = await octokit.repos.getContent({path: 'private/_.ts', repo: 'Daggerbot-Private', ...this.repositoryConfig});
|
||||||
|
return data as IDataContent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,6 @@ client.on('raw', async (packet:RawGatewayPacket<RawMessageUpdate>)=>{
|
|||||||
const channel = client.channels.cache.get(packet.d.channel_id) as Discord.TextBasedChannel;
|
const channel = client.channels.cache.get(packet.d.channel_id) as Discord.TextBasedChannel;
|
||||||
const old_message = await channel.messages.fetch(packet.d.id);
|
const old_message = await channel.messages.fetch(packet.d.id);
|
||||||
const new_message = await channel.messages.fetch(packet.d.id);
|
const new_message = await channel.messages.fetch(packet.d.id);
|
||||||
if (old_message.content === new_message.content) return;
|
|
||||||
|
|
||||||
client.emit('messageUpdate', old_message, new_message);
|
client.emit('messageUpdate', old_message, new_message);
|
||||||
});
|
});
|
||||||
|
@ -55,6 +55,7 @@ export class MPServerSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
async fetchPlayerData(serverName:string) {
|
async fetchPlayerData(serverName:string) {
|
||||||
const findServerByName = await this.model.findOne({where: {serverName: serverName}});
|
const findServerByName = await this.model.findOne({where: {serverName: serverName}});
|
||||||
if (findServerByName) return findServerByName.dataValues.playerData;
|
if (findServerByName) return findServerByName.dataValues.playerData;
|
||||||
|
@ -30,6 +30,7 @@ export class DailyMsgsSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
nukeDays = async()=>await this.model.destroy({truncate: true});
|
nukeDays = async()=>await this.model.destroy({truncate: true});
|
||||||
fetchDays = async()=>await this.model.findAll();
|
fetchDays = async()=>await this.model.findAll();
|
||||||
async newDay(formattedDate:number, total:number) {
|
async newDay(formattedDate:number, total:number) {
|
||||||
|
@ -25,6 +25,7 @@ export class ProhibitedWordsSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
findWord = async(word:string)=>await this.model.findByPk(word);
|
findWord = async(word:string)=>await this.model.findByPk(word);
|
||||||
getAllWords = async()=>await this.model.findAll();
|
getAllWords = async()=>await this.model.findAll();
|
||||||
insertWord = async(word:string)=>await this.model.create({word: word});
|
insertWord = async(word:string)=>await this.model.create({word: word});
|
||||||
|
@ -83,6 +83,7 @@ export class PunishmentsSvc {
|
|||||||
});
|
});
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
async updateReason(caseId:number, reason:string) {
|
async updateReason(caseId:number, reason:string) {
|
||||||
const findCase = this.findCase(caseId);
|
const findCase = this.findCase(caseId);
|
||||||
if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}});
|
if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}});
|
||||||
|
@ -40,6 +40,7 @@ export class SuggestionsSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
fetchById = async(id:number)=>await this.model.findByPk(id);
|
fetchById = async(id:number)=>await this.model.findByPk(id);
|
||||||
updateStatus = async(id:number, status:string)=>await this.model.update({status: status}, {where: {id: id}});
|
updateStatus = async(id:number, status:string)=>await this.model.update({status: status}, {where: {id: id}});
|
||||||
create =(userid:string, description:string)=>this.model.create({userid: userid, suggestion: description, status: 'Pending'})
|
create =(userid:string, description:string)=>this.model.create({userid: userid, suggestion: description, status: 'Pending'})
|
||||||
|
@ -50,6 +50,7 @@ export class TagSystemSvc {
|
|||||||
});
|
});
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
async createTag(userid:string, tagName:string, message:string, embedFlag:boolean) {
|
async createTag(userid:string, tagName:string, message:string, embedFlag:boolean) {
|
||||||
CacheServer.delete('tags');
|
CacheServer.delete('tags');
|
||||||
return await this.model.create({userid: userid, tagname: tagName, message: message.replace(/\\n/g, '\n'), embedFlag: embedFlag});
|
return await this.model.create({userid: userid, tagname: tagName, message: message.replace(/\\n/g, '\n'), embedFlag: embedFlag});
|
||||||
|
@ -57,6 +57,7 @@ export class UserLevelsSvc {
|
|||||||
});
|
});
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
fetchEveryone = async()=>await this.model.findAll();
|
fetchEveryone = async()=>await this.model.findAll();
|
||||||
fetchUser = async(userId:string)=>await this.model.findByPk(userId);
|
fetchUser = async(userId:string)=>await this.model.findByPk(userId);
|
||||||
deleteUser = async(userId:string)=>await this.model.destroy({where: {id: userId}});
|
deleteUser = async(userId:string)=>await this.model.destroy({where: {id: userId}});
|
||||||
|
@ -34,6 +34,7 @@ export class YouTubeChannelsSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
|
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
|
||||||
async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) {
|
async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) {
|
||||||
if (await this.model.findOne({where: {ytchannel: YTChannelID}})) return false;
|
if (await this.model.findOne({where: {ytchannel: YTChannelID}})) return false;
|
||||||
await this.model.create({ytchannel: YTChannelID, dcchannel: DCChannelID, dcrole: DCRole});
|
await this.model.create({ytchannel: YTChannelID, dcchannel: DCChannelID, dcrole: DCRole});
|
||||||
|
Loading…
Reference in New Issue
Block a user