mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 08:20:58 -05:00
Compare commits
2 Commits
ad6c92a8d0
...
611fa5867b
Author | SHA1 | Date | |
---|---|---|---|
|
611fa5867b | ||
|
b71db7b252 |
@ -1,6 +0,0 @@
|
|||||||
# main; node:19.9.0-alpine3.18
|
|
||||||
# backup; node:current-bookworm
|
|
||||||
FROM node:19.9.0-alpine3.18
|
|
||||||
WORKDIR /bot
|
|
||||||
RUN yarn
|
|
||||||
CMD ["yarn", "node", "dist/index.js"]
|
|
@ -1,9 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
bot:
|
|
||||||
container_name: 'Daggerbot'
|
|
||||||
image: 'git.toast-server.net/toast/daggerbot-ts:alpine'
|
|
||||||
volumes:
|
|
||||||
- .:/bot
|
|
||||||
network_mode: host
|
|
@ -26,6 +26,7 @@
|
|||||||
"yarn": ">=3.6.1",
|
"yarn": ">=3.6.1",
|
||||||
"npm": "please use yarn instead of npm"
|
"npm": "please use yarn instead of npm"
|
||||||
},
|
},
|
||||||
|
"engineStrict": true,
|
||||||
"packageManager": "yarn@3.6.3",
|
"packageManager": "yarn@3.6.3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discord-player/extractor": "4.4.1",
|
"@discord-player/extractor": "4.4.1",
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
|
interface repeatedMessages {
|
||||||
|
[key: string]: {data: Discord.Collection<number,{type:string,channel:string}>,timeout: NodeJS.Timeout}
|
||||||
|
}
|
||||||
|
type MPServerCache = Record<string,{
|
||||||
|
players: FSPlayer[],
|
||||||
|
status: 'online' | 'offline' | null,
|
||||||
|
name: string | null
|
||||||
|
}>
|
||||||
|
type YouTubeCache = Record<string,string>
|
||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import {readFileSync, readdirSync} from 'node:fs';
|
import {readFileSync, readdirSync} from 'node:fs';
|
||||||
import {Tokens, Config, repeatedMessages, type MPServerCache} from './typings/interfaces';
|
import {Tokens, Config, FSPlayer} from './typings/interfaces';
|
||||||
import bannedWords from './models/bannedWords.js';
|
import bannedWords from './models/bannedWords.js';
|
||||||
import userLevels from './models/userLevels.js';
|
import userLevels from './models/userLevels.js';
|
||||||
import suggestion from './models/suggestion.js';
|
import suggestion from './models/suggestion.js';
|
||||||
@ -29,11 +38,10 @@ export default class TClient extends Discord.Client {
|
|||||||
registry: Array<Discord.ApplicationCommandDataResolvable>;
|
registry: Array<Discord.ApplicationCommandDataResolvable>;
|
||||||
config: Config;
|
config: Config;
|
||||||
tokens: Tokens;
|
tokens: Tokens;
|
||||||
YTCache: any;
|
YTCache: YouTubeCache = {};
|
||||||
embed: typeof Discord.EmbedBuilder;
|
embed: typeof Discord.EmbedBuilder;
|
||||||
collection: any;
|
collection: typeof Discord.Collection;
|
||||||
messageCollector: any;
|
attachmentBuilder: typeof Discord.AttachmentBuilder;
|
||||||
attachmentBuilder: any;
|
|
||||||
moment: typeof moment;
|
moment: typeof moment;
|
||||||
xjs: typeof xjs;
|
xjs: typeof xjs;
|
||||||
userLevels: userLevels;
|
userLevels: userLevels;
|
||||||
@ -67,10 +75,9 @@ export default class TClient extends Discord.Client {
|
|||||||
this.YTCache = {
|
this.YTCache = {
|
||||||
'UCQ8k8yTDLITldfWYKDs3xFg': undefined, // Daggerwin
|
'UCQ8k8yTDLITldfWYKDs3xFg': undefined, // Daggerwin
|
||||||
'UCguI73--UraJpso4NizXNzA': undefined // Machinery Restorer
|
'UCguI73--UraJpso4NizXNzA': undefined // Machinery Restorer
|
||||||
}
|
} as YouTubeCache;
|
||||||
this.embed = Discord.EmbedBuilder;
|
this.embed = Discord.EmbedBuilder;
|
||||||
this.collection = Discord.Collection;
|
this.collection = Discord.Collection;
|
||||||
this.messageCollector = Discord.MessageCollector;
|
|
||||||
this.attachmentBuilder = Discord.AttachmentBuilder;
|
this.attachmentBuilder = Discord.AttachmentBuilder;
|
||||||
this.moment = moment;
|
this.moment = moment;
|
||||||
this.xjs = xjs;
|
this.xjs = xjs;
|
||||||
@ -83,12 +90,12 @@ export default class TClient extends Discord.Client {
|
|||||||
this.suggestion = new suggestion(this);
|
this.suggestion = new suggestion(this);
|
||||||
this.tags = new tags(this);
|
this.tags = new tags(this);
|
||||||
this.repeatedMessages = {};
|
this.repeatedMessages = {};
|
||||||
this.setMaxListeners(45);
|
this.setMaxListeners(62);
|
||||||
this.statsGraph = -120;
|
this.statsGraph = -120;
|
||||||
}
|
}
|
||||||
async init(){
|
async init(){
|
||||||
console.time('Startup');
|
console.time('Startup');
|
||||||
await DatabaseServer(this);
|
DatabaseServer.connect(this);
|
||||||
this.login(this.tokens.main);
|
this.login(this.tokens.main);
|
||||||
for (const file of readdirSync('dist/events')){
|
for (const file of readdirSync('dist/events')){
|
||||||
const eventFile = await import(`./events/${file}`);
|
const eventFile = await import(`./events/${file}`);
|
||||||
|
@ -5,7 +5,7 @@ import canvas from 'canvas';
|
|||||||
import FormatPlayer from '../helpers/FormatPlayer.js';
|
import FormatPlayer from '../helpers/FormatPlayer.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
import {readFileSync} from 'node:fs';
|
import {readFileSync} from 'node:fs';
|
||||||
import {FSData} from '../typings/interfaces.js';
|
import {FSData} from '../typings/interfaces';
|
||||||
|
|
||||||
const serverChoices = [
|
const serverChoices = [
|
||||||
{name: 'Main Server', value: 'mainServer'},
|
{name: 'Main Server', value: 'mainServer'},
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import TClient from '../client';
|
import TClient from '../client';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
import LogPrefix from '../helpers/LogPrefix.js';
|
||||||
|
|
||||||
export default async(client:TClient)=>{
|
const connection:mongoose.Connection = mongoose.connection;
|
||||||
const LogPrefix = '[DATABASE]';
|
export default class DatabaseServer {
|
||||||
mongoose.set('strictQuery', true);
|
static connect(client: TClient) {
|
||||||
|
const Logger = (logType:'log'|'error', msg:string)=>console[logType](client.logTime(), `${LogPrefix('DATABASE')} ${msg}`);
|
||||||
|
|
||||||
const connection = mongoose.connection;
|
connection.set('strictQuery', true);
|
||||||
connection.openUri(client.tokens.mongodb_uri, {
|
connection.openUri(client.tokens.mongodb_uri, {
|
||||||
replicaSet: 'toastyy',
|
replicaSet: 'toastyy',
|
||||||
autoIndex: true,
|
autoIndex: true,
|
||||||
@ -19,12 +21,13 @@ export default async(client:TClient)=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.on('connecting', ()=>console.log(client.logTime(), `${LogPrefix} Establishing connection to MongoDB`))
|
.on('connecting', ()=>Logger('log','Establishing connection to MongoDB'))
|
||||||
.on('connected', ()=>console.log(client.logTime(), `${LogPrefix} Connection to MongoDB has been established`))
|
.on('connected', ()=>Logger('log','Connection to MongoDB has been established'))
|
||||||
.on('disconnecting', ()=>console.log(client.logTime(), `${LogPrefix} Disconnecting from MongoDB`))
|
.on('disconnecting', ()=>Logger('log','Disconnecting from MongoDB'))
|
||||||
.on('disconnected', ()=>console.log(client.logTime(), `${LogPrefix} Disconnected from MongoDB`))
|
.on('disconnected', ()=>Logger('log','Disconnected from MongoDB'))
|
||||||
.on('close', ()=>console.log(client.logTime(), `${LogPrefix} MongoDB has closed the connection`))
|
.on('close', ()=>Logger('log','MongoDB has closed the connection'))
|
||||||
.on('all', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to all members`))
|
.on('all', ()=>Logger('log','Successfully established a connection to all members'))
|
||||||
.on('fullsetup', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to Primary server & atleast one member`))
|
.on('fullsetup', ()=>Logger('log','Successfully established a connection to Primary server & atleast one member'))
|
||||||
.on('error', (err:mongoose.Error)=>console.error(client.logTime(), `${LogPrefix} Encountered an error in MongoDB: ${err.message}`));
|
.on('error', (err:mongoose.Error)=>Logger('error',`Encountered an error in MongoDB: ${err.message}`));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
|
interface TServer {
|
||||||
|
ip: string
|
||||||
|
code: string
|
||||||
|
}
|
||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client';
|
import TClient from '../client';
|
||||||
import FormatPlayer from '../helpers/FormatPlayer.js';
|
import FormatPlayer from '../helpers/FormatPlayer.js';
|
||||||
|
import LogPrefix from '../helpers/LogPrefix.js';
|
||||||
import {writeFileSync, readFileSync} from 'node:fs';
|
import {writeFileSync, readFileSync} from 'node:fs';
|
||||||
import {FSPlayer, FSData, FSCareerSavegame, TServer} from '../typings/interfaces';
|
import {FSPlayer, FSData, FSCareerSavegame} from '../typings/interfaces';
|
||||||
|
|
||||||
export default async(client:TClient, Channel:string, Message:string, Server:TServer, ServerName:string)=>{
|
export default async(client:TClient, Channel:string, Message:string, Server:TServer, ServerName:string)=>{
|
||||||
let MPLoopPrefix = '[MPLoop] ';
|
|
||||||
let isServerOnline = false;
|
let isServerOnline = false;
|
||||||
let playerData:Array<string> = [];
|
let playerData:Array<string> = [];
|
||||||
let noContentImage = 'https://cdn.discordapp.com/attachments/1118960531135541318/1140906691236479036/68efx1.png';
|
let noContentImage = 'https://cdn.discordapp.com/attachments/1118960531135541318/1140906691236479036/68efx1.png';
|
||||||
@ -20,7 +24,7 @@ export default async(client:TClient, Channel:string, Message:string, Server:TSer
|
|||||||
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
||||||
|
|
||||||
if (!hitDSS ?? !hitCSG){
|
if (!hitDSS ?? !hitCSG){
|
||||||
if (hitDSS && !hitDSS.slots) return new Error(`${MPLoopPrefix}DSS failed with unknown slots table for ${client.MPServerCache[ServerName].name}`);
|
if (hitDSS && !hitDSS.slots) return new Error(`${LogPrefix('MPLoop')} DSS failed with unknown slots table for ${client.MPServerCache[ServerName].name}`);
|
||||||
if (hitDSS && !hitCSG) return msg.edit({content: 'No savegame found or autosave has ran.', embeds: [genericEmbed.setColor(client.config.embedColorOrange).setImage(noContentImage)]});
|
if (hitDSS && !hitCSG) return msg.edit({content: 'No savegame found or autosave has ran.', embeds: [genericEmbed.setColor(client.config.embedColorOrange).setImage(noContentImage)]});
|
||||||
else return msg.edit({embeds: [serverErrorEmbed]});
|
else return msg.edit({embeds: [serverErrorEmbed]});
|
||||||
}
|
}
|
1
src/helpers/LogPrefix.ts
Normal file
1
src/helpers/LogPrefix.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default (prefix:string)=>{ return `[${prefix}]` };
|
12
src/index.ts
12
src/index.ts
@ -2,8 +2,8 @@ import Discord from 'discord.js';
|
|||||||
import TClient from './client.js';
|
import TClient from './client.js';
|
||||||
const client = new TClient;
|
const client = new TClient;
|
||||||
client.init();
|
client.init();
|
||||||
import YTLoop from './funcs/YTLoop.js';
|
import YTModule from './funcs/YTModule.js';
|
||||||
import MPLoop from './funcs/MPLoop.js';
|
import MPModule from './funcs/MPModule.js';
|
||||||
import {Player} from 'discord-player';
|
import {Player} from 'discord-player';
|
||||||
const player = Player.singleton(client);
|
const player = Player.singleton(client);
|
||||||
import MessageTool from './helpers/MessageTool.js';
|
import MessageTool from './helpers/MessageTool.js';
|
||||||
@ -36,18 +36,18 @@ if (client.config.botSwitches.music){
|
|||||||
// YouTube Upload notification and MP loop
|
// YouTube Upload notification and MP loop
|
||||||
if (client.config.botSwitches.mpstats) setInterval(async()=>{
|
if (client.config.botSwitches.mpstats) setInterval(async()=>{
|
||||||
const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id));
|
const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id));
|
||||||
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPLoop(client, locArea.channel, locArea.message, serverlake[locName], locName)
|
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPModule(client, locArea.channel, locArea.message, serverlake[locName], locName)
|
||||||
}, 35000);
|
}, 35000);
|
||||||
setInterval(async()=>{// Ping notification is currently WIP, it might be active in production but I want to see how it goes with role mentions first so I can make any further changes.
|
setInterval(async()=>{// Ping notification is currently WIP, it might be active in production but I want to see how it goes with role mentions first so I can make any further changes.
|
||||||
YTLoop(client, 'UCQ8k8yTDLITldfWYKDs3xFg', 'Daggerwin', '528967918772551702', '1011341005389307925'); // 528967918772551702 = #videos-and-streams; 1011341005389307925 = Bot Tech;
|
YTModule(client, 'UCQ8k8yTDLITldfWYKDs3xFg', 'Daggerwin', '528967918772551702', '1011341005389307925'); // 528967918772551702 = #videos-and-streams; 1011341005389307925 = Bot Tech;
|
||||||
YTLoop(client, 'UCguI73--UraJpso4NizXNzA', 'Machinery Restorer', '767444045520961567', '989591094524276796') // 767444045520961567 = #machinery-restorer; 989591094524276796 = Temp;
|
YTModule(client, 'UCguI73--UraJpso4NizXNzA', 'Machinery Restorer', '767444045520961567', '989591094524276796') // 767444045520961567 = #machinery-restorer; 989591094524276796 = Temp;
|
||||||
}, 300000)
|
}, 300000)
|
||||||
|
|
||||||
// Event loop for punishments and daily msgs
|
// Event loop for punishments and daily msgs
|
||||||
setInterval(async()=>{
|
setInterval(async()=>{
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const punishments = await client.punishments._content.find({});
|
const punishments = await client.punishments._content.find();
|
||||||
punishments.filter(x=>x.endTime && x.endTime<= now && !x.expired).forEach(async punishment=>{
|
punishments.filter(x=>x.endTime && x.endTime<= now && !x.expired).forEach(async punishment=>{
|
||||||
console.log(client.logTime(), `${punishment.member}\'s ${punishment.type} should expire now`);
|
console.log(client.logTime(), `${punishment.member}\'s ${punishment.type} should expire now`);
|
||||||
console.log(client.logTime(), await client.punishments.removePunishment(punishment._id, client.user.id, 'Time\'s up!'));
|
console.log(client.logTime(), await client.punishments.removePunishment(punishment._id, client.user.id, 'Time\'s up!'));
|
||||||
|
@ -3,7 +3,7 @@ import TClient from '../client.js';
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
import FormatTime from '../helpers/FormatTime.js';
|
import FormatTime from '../helpers/FormatTime.js';
|
||||||
import {Punishment} from '../typings/interfaces.js';
|
import {Punishment} from '../typings/interfaces';
|
||||||
|
|
||||||
const Schema = mongoose.model('punishments', new mongoose.Schema({
|
const Schema = mongoose.model('punishments', new mongoose.Schema({
|
||||||
_id: {type: Number, required: true},
|
_id: {type: Number, required: true},
|
||||||
|
21
src/typings/interfaces.d.ts
vendored
21
src/typings/interfaces.d.ts
vendored
@ -1,17 +1,5 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
|
|
||||||
export interface UserLevels {
|
|
||||||
messages: number,
|
|
||||||
level: number
|
|
||||||
}
|
|
||||||
export interface punOpt {
|
|
||||||
time?: string,
|
|
||||||
reason?: string,
|
|
||||||
interaction?: Discord.ChatInputCommandInteraction<"cached">
|
|
||||||
}
|
|
||||||
export interface repeatedMessages {
|
|
||||||
[key:string]: {data: Discord.Collection<number,{type:string,channel:string}>, timeout: NodeJS.Timeout}
|
|
||||||
}
|
|
||||||
export interface Punishment {
|
export interface Punishment {
|
||||||
_id: number;
|
_id: number;
|
||||||
type: string;
|
type: string;
|
||||||
@ -187,12 +175,3 @@ export interface Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type MPServerCache = Record<string,{
|
|
||||||
players: FSPlayer[],
|
|
||||||
status: 'online' | 'offline' | null,
|
|
||||||
name: string | null
|
|
||||||
}>
|
|
||||||
export interface TServer {
|
|
||||||
ip: string
|
|
||||||
code: string
|
|
||||||
}
|
|
@ -12,8 +12,8 @@
|
|||||||
"rootDir": "src/",
|
"rootDir": "src/",
|
||||||
"outDir": "dist/",
|
"outDir": "dist/",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"typeRoots": [ "./src/typings" ],
|
"typeRoots": [ "./src/typings" ]
|
||||||
},
|
},
|
||||||
"include": [ "src/" ],
|
"include": [ "src/" ],
|
||||||
"exclude": [ ".yarn/cache", ".yarn/unplugged",".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ]
|
"exclude": [ ".yarn/cache", ".yarn/unplugged", ".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user