1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 12:30:58 -04:00

Compare commits

..

No commits in common. "611fa5867bee105afae40f2c80d781839e9595c6" and "ad6c92a8d0f6c48648dd804d7abec3a8532ce1e6" have entirely different histories.

14 changed files with 83 additions and 62 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
engine-strict = true

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
# 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"]

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
version: '3'
services:
bot:
container_name: 'Daggerbot'
image: 'git.toast-server.net/toast/daggerbot-ts:alpine'
volumes:
- .:/bot
network_mode: host

View File

@ -26,7 +26,6 @@
"yarn": ">=3.6.1",
"npm": "please use yarn instead of npm"
},
"engineStrict": true,
"packageManager": "yarn@3.6.3",
"dependencies": {
"@discord-player/extractor": "4.4.1",

View File

@ -1,15 +1,6 @@
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 {readFileSync, readdirSync} from 'node:fs';
import {Tokens, Config, FSPlayer} from './typings/interfaces';
import {Tokens, Config, repeatedMessages, type MPServerCache} from './typings/interfaces';
import bannedWords from './models/bannedWords.js';
import userLevels from './models/userLevels.js';
import suggestion from './models/suggestion.js';
@ -38,10 +29,11 @@ export default class TClient extends Discord.Client {
registry: Array<Discord.ApplicationCommandDataResolvable>;
config: Config;
tokens: Tokens;
YTCache: YouTubeCache = {};
YTCache: any;
embed: typeof Discord.EmbedBuilder;
collection: typeof Discord.Collection;
attachmentBuilder: typeof Discord.AttachmentBuilder;
collection: any;
messageCollector: any;
attachmentBuilder: any;
moment: typeof moment;
xjs: typeof xjs;
userLevels: userLevels;
@ -75,9 +67,10 @@ export default class TClient extends Discord.Client {
this.YTCache = {
'UCQ8k8yTDLITldfWYKDs3xFg': undefined, // Daggerwin
'UCguI73--UraJpso4NizXNzA': undefined // Machinery Restorer
} as YouTubeCache;
}
this.embed = Discord.EmbedBuilder;
this.collection = Discord.Collection;
this.messageCollector = Discord.MessageCollector;
this.attachmentBuilder = Discord.AttachmentBuilder;
this.moment = moment;
this.xjs = xjs;
@ -90,12 +83,12 @@ export default class TClient extends Discord.Client {
this.suggestion = new suggestion(this);
this.tags = new tags(this);
this.repeatedMessages = {};
this.setMaxListeners(62);
this.setMaxListeners(45);
this.statsGraph = -120;
}
async init(){
console.time('Startup');
DatabaseServer.connect(this);
await DatabaseServer(this);
this.login(this.tokens.main);
for (const file of readdirSync('dist/events')){
const eventFile = await import(`./events/${file}`);

View File

@ -5,7 +5,7 @@ import canvas from 'canvas';
import FormatPlayer from '../helpers/FormatPlayer.js';
import MessageTool from '../helpers/MessageTool.js';
import {readFileSync} from 'node:fs';
import {FSData} from '../typings/interfaces';
import {FSData} from '../typings/interfaces.js';
const serverChoices = [
{name: 'Main Server', value: 'mainServer'},

View File

@ -1,13 +1,11 @@
import TClient from '../client';
import mongoose from 'mongoose';
import LogPrefix from '../helpers/LogPrefix.js';
const connection:mongoose.Connection = mongoose.connection;
export default class DatabaseServer {
static connect(client: TClient) {
const Logger = (logType:'log'|'error', msg:string)=>console[logType](client.logTime(), `${LogPrefix('DATABASE')} ${msg}`);
export default async(client:TClient)=>{
const LogPrefix = '[DATABASE]';
mongoose.set('strictQuery', true);
connection.set('strictQuery', true);
const connection = mongoose.connection;
connection.openUri(client.tokens.mongodb_uri, {
replicaSet: 'toastyy',
autoIndex: true,
@ -21,13 +19,12 @@ export default class DatabaseServer {
});
connection
.on('connecting', ()=>Logger('log','Establishing connection to MongoDB'))
.on('connected', ()=>Logger('log','Connection to MongoDB has been established'))
.on('disconnecting', ()=>Logger('log','Disconnecting from MongoDB'))
.on('disconnected', ()=>Logger('log','Disconnected from MongoDB'))
.on('close', ()=>Logger('log','MongoDB has closed the connection'))
.on('all', ()=>Logger('log','Successfully established a connection to all members'))
.on('fullsetup', ()=>Logger('log','Successfully established a connection to Primary server & atleast one member'))
.on('error', (err:mongoose.Error)=>Logger('error',`Encountered an error in MongoDB: ${err.message}`));
}
.on('connecting', ()=>console.log(client.logTime(), `${LogPrefix} Establishing connection to MongoDB`))
.on('connected', ()=>console.log(client.logTime(), `${LogPrefix} Connection to MongoDB has been established`))
.on('disconnecting', ()=>console.log(client.logTime(), `${LogPrefix} Disconnecting from MongoDB`))
.on('disconnected', ()=>console.log(client.logTime(), `${LogPrefix} Disconnected from MongoDB`))
.on('close', ()=>console.log(client.logTime(), `${LogPrefix} MongoDB has closed the connection`))
.on('all', ()=>console.log(client.logTime(), `${LogPrefix} 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('error', (err:mongoose.Error)=>console.error(client.logTime(), `${LogPrefix} Encountered an error in MongoDB: ${err.message}`));
}

View File

@ -1,15 +1,11 @@
interface TServer {
ip: string
code: string
}
import Discord from 'discord.js';
import TClient from '../client';
import FormatPlayer from '../helpers/FormatPlayer.js';
import LogPrefix from '../helpers/LogPrefix.js';
import {writeFileSync, readFileSync} from 'node:fs';
import {FSPlayer, FSData, FSCareerSavegame} from '../typings/interfaces';
import {FSPlayer, FSData, FSCareerSavegame, TServer} from '../typings/interfaces';
export default async(client:TClient, Channel:string, Message:string, Server:TServer, ServerName:string)=>{
let MPLoopPrefix = '[MPLoop] ';
let isServerOnline = false;
let playerData:Array<string> = [];
let noContentImage = 'https://cdn.discordapp.com/attachments/1118960531135541318/1140906691236479036/68efx1.png';
@ -24,7 +20,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);
if (!hitDSS ?? !hitCSG){
if (hitDSS && !hitDSS.slots) return new Error(`${LogPrefix('MPLoop')} DSS failed with unknown slots table for ${client.MPServerCache[ServerName].name}`);
if (hitDSS && !hitDSS.slots) return new Error(`${MPLoopPrefix}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)]});
else return msg.edit({embeds: [serverErrorEmbed]});
}

View File

@ -1 +0,0 @@
export default (prefix:string)=>{ return `[${prefix}]` };

View File

@ -2,8 +2,8 @@ import Discord from 'discord.js';
import TClient from './client.js';
const client = new TClient;
client.init();
import YTModule from './funcs/YTModule.js';
import MPModule from './funcs/MPModule.js';
import YTLoop from './funcs/YTLoop.js';
import MPLoop from './funcs/MPLoop.js';
import {Player} from 'discord-player';
const player = Player.singleton(client);
import MessageTool from './helpers/MessageTool.js';
@ -36,18 +36,18 @@ if (client.config.botSwitches.music){
// YouTube Upload notification and MP loop
if (client.config.botSwitches.mpstats) setInterval(async()=>{
const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id));
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPModule(client, locArea.channel, locArea.message, serverlake[locName], locName)
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPLoop(client, locArea.channel, locArea.message, serverlake[locName], locName)
}, 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.
YTModule(client, 'UCQ8k8yTDLITldfWYKDs3xFg', 'Daggerwin', '528967918772551702', '1011341005389307925'); // 528967918772551702 = #videos-and-streams; 1011341005389307925 = Bot Tech;
YTModule(client, 'UCguI73--UraJpso4NizXNzA', 'Machinery Restorer', '767444045520961567', '989591094524276796') // 767444045520961567 = #machinery-restorer; 989591094524276796 = Temp;
YTLoop(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;
}, 300000)
// Event loop for punishments and daily msgs
setInterval(async()=>{
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=>{
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!'));

View File

@ -3,7 +3,7 @@ import TClient from '../client.js';
import mongoose from 'mongoose';
import ms from 'ms';
import FormatTime from '../helpers/FormatTime.js';
import {Punishment} from '../typings/interfaces';
import {Punishment} from '../typings/interfaces.js';
const Schema = mongoose.model('punishments', new mongoose.Schema({
_id: {type: Number, required: true},

View File

@ -1,5 +1,17 @@
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 {
_id: number;
type: string;
@ -175,3 +187,12 @@ export interface Config {
}
}
}
export type MPServerCache = Record<string,{
players: FSPlayer[],
status: 'online' | 'offline' | null,
name: string | null
}>
export interface TServer {
ip: string
code: string
}

View File

@ -12,7 +12,7 @@
"rootDir": "src/",
"outDir": "dist/",
"moduleResolution": "bundler",
"typeRoots": [ "./src/typings" ]
"typeRoots": [ "./src/typings" ],
},
"include": [ "src/" ],
"exclude": [ ".yarn/cache", ".yarn/unplugged",".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ]