mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-18 00:31:00 -05:00
Compare commits
3 Commits
670c5782ba
...
21413b7e52
Author | SHA1 | Date | |
---|---|---|---|
|
21413b7e52 | ||
|
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
|
||||||
|
2
.pnp.cjs
generated
2
.pnp.cjs
generated
@ -26,7 +26,6 @@ const RAW_RUNTIME_STATE =
|
|||||||
[null, {\
|
[null, {\
|
||||||
"packageLocation": "./",\
|
"packageLocation": "./",\
|
||||||
"packageDependencies": [\
|
"packageDependencies": [\
|
||||||
["@octokit/auth-token", "npm:4.0.0"],\
|
|
||||||
["@octokit/rest", "npm:20.0.2"],\
|
["@octokit/rest", "npm:20.0.2"],\
|
||||||
["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
|
["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
|
||||||
["@types/ms", "npm:0.7.34"],\
|
["@types/ms", "npm:0.7.34"],\
|
||||||
@ -991,7 +990,6 @@ const RAW_RUNTIME_STATE =
|
|||||||
"packageLocation": "./",\
|
"packageLocation": "./",\
|
||||||
"packageDependencies": [\
|
"packageDependencies": [\
|
||||||
["daggerbot-ts", "workspace:."],\
|
["daggerbot-ts", "workspace:."],\
|
||||||
["@octokit/auth-token", "npm:4.0.0"],\
|
|
||||||
["@octokit/rest", "npm:20.0.2"],\
|
["@octokit/rest", "npm:20.0.2"],\
|
||||||
["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
|
["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
|
||||||
["@types/ms", "npm:0.7.34"],\
|
["@types/ms", "npm:0.7.34"],\
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
"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",
|
|
||||||
"@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",
|
||||||
|
@ -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}**`,
|
||||||
@ -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
|
||||||
|
@ -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};
|
||||||
|
@ -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);
|
||||||
});
|
});
|
||||||
|
@ -149,7 +149,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@octokit/auth-token@npm:4.0.0, @octokit/auth-token@npm:^4.0.0":
|
"@octokit/auth-token@npm:^4.0.0":
|
||||||
version: 4.0.0
|
version: 4.0.0
|
||||||
resolution: "@octokit/auth-token@npm:4.0.0"
|
resolution: "@octokit/auth-token@npm:4.0.0"
|
||||||
checksum: 10/60e42701e341d700f73c518c7a35675d36d79fa9d5e838cc3ade96d147e49f5ba74db2e07b2337c2b95aaa540aa42088116df2122daa25633f9e70a2c8785c44
|
checksum: 10/60e42701e341d700f73c518c7a35675d36d79fa9d5e838cc3ade96d147e49f5ba74db2e07b2337c2b95aaa540aa42088116df2122daa25633f9e70a2c8785c44
|
||||||
@ -744,7 +744,6 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "daggerbot-ts@workspace:."
|
resolution: "daggerbot-ts@workspace:."
|
||||||
dependencies:
|
dependencies:
|
||||||
"@octokit/auth-token": "npm:4.0.0"
|
|
||||||
"@octokit/rest": "npm:20.0.2"
|
"@octokit/rest": "npm:20.0.2"
|
||||||
"@toast/tokenservice-client": "npm:1.0.11"
|
"@toast/tokenservice-client": "npm:1.0.11"
|
||||||
"@types/ms": "npm:0.7.34"
|
"@types/ms": "npm:0.7.34"
|
||||||
|
Loading…
Reference in New Issue
Block a user