Ok I just had to redo the whole damn thing because it wouldnt start correctly

This commit is contained in:
Christopher Cookman 2023-09-12 23:43:56 -06:00
parent 3f768e4426
commit e2cae8fbb8
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

120
index.js
View file

@ -1,29 +1,21 @@
const config = require("./config.json"); const config = require("./config.json");
const fs = require("fs");
const colors = require("colors"); const colors = require("colors");
const axios = require("axios"); const axios = require("axios");
const fs = require("fs");
const SteamUser = require("steam-user"); const SteamUser = require("steam-user");
const TeamFortress2 = require("tf2"); const TeamFortress2 = require("tf2");
const Discord = require("discord.js"); const Discord = require("discord.js");
const { emit } = require("process"); const bot = new Discord.Client({intents: ["GuildMessages", "Guilds", "MessageContent"]});
const bot = new Discord.Client({ intents: ["GuildMessages", "Guilds", "MessageContent"] }); const ring_hook = new Discord.WebhookClient({"url": config.discord.ring_webhook});
const ring_hook = new Discord.WebhookClient({ "url": config.discord.ring_webhook }); const notif_hook = new Discord.WebhookClient({"url": config.discord.notification_webhook}, {"allowedMentions": false});
const notif_hook = new Discord.WebhookClient({ "url": config.discord.notification_webhook }, { "allowedMentions": false }); const pan_hook = new Discord.WebhookClient({"url": config.discord.pan_webhook});
const pan_hook = new Discord.WebhookClient({ "url": config.discord.pan_webhook }); const user = new SteamUser();
let user = new SteamUser(); const tf2 = new TeamFortress2(user);
let tf2 = new TeamFortress2(user);
user.on("loggedOn", async (stuff) => { user.on("loggedOn", (stuff) => {
//user.setPersona(1); //Just needed this to check that it was logging in properly, and not false reporting a successful log in lol //user.setPersona(1); //Just needed this to check that it was logging in properly, and not false reporting a successful log in lol
console.log(`${colors.cyan("[Steam]")} Logged into steam`) console.log(`${colors.cyan("[Steam]")} Logged into steam`)
await user.gamesPlayed([440]); user.gamesPlayed([440]);
})
tf2.on("connectedToGC", async (ver) => {
console.log(`${colors.yellow("[TF2]")} Connected to GC, version: ${ver}`)
// Get lang file from tf wiki https://wiki.teamfortress.com/w/images/c/cf/Tf_english.txt
console.log(`${colors.green("[Lang]")} Getting TF2 Lang File from wiki`);
axios.get("https://wiki.teamfortress.com/w/images/c/cf/Tf_english.txt").then((res) => { axios.get("https://wiki.teamfortress.com/w/images/c/cf/Tf_english.txt").then((res) => {
console.log(`${colors.green("[Lang]")} Got TF2 Lang File from wiki`); console.log(`${colors.green("[Lang]")} Got TF2 Lang File from wiki`);
// set lang from body // set lang from body
@ -45,71 +37,55 @@ tf2.on("connectedToGC", async (ver) => {
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`); console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
} }
}) })
// Startup time in formatted Mm ss
const startupTime = `${Math.floor((Date.now() - initTime) / 60000)}m ${Math.floor((Date.now() - initTime) / 1000) % 60}s`;
console.log(`${colors.cyan("[INFO]")} Startup took ${startupTime}`);
}) })
tf2.on("disconnectedFromGC", (reason) => { tf2.on("connectedToGC", (ver) => {
console.log(`${colors.yellow("[TF2]")} Disconnected from GC, reason: ${reason}`) console.log(`${colors.yellow("TF2")} Connected to GC`)
console.log(`${colors.blue("[Info]")} Startup took ${Date.now() - initTime}ms`)
}) })
tf2.on("systemMessage", (msg) => { tf2.on("systemMessage", (msg) => {
console.log(`${colors.yellow("[TF2]")} New System Message: ${msg}`) console.log(`[TF2] New System Message: ${msg}`)
notif_hook.send({ notif_hook.send({embeds: [
embeds: [ {
{ description: msg,
description: `<:Messages:1151242960655089744> ${msg}`, color: Discord.Colors.Blue
color: 0x3498DB }
} ]})
]
})
}) })
tf2.on("itemBroadcast", (msg, username, wasDestruction, defindex) => { tf2.on("itemBroadcast", (msg, username, wasDestruction, defindex) => {
console.log(`${colors.yellow("[TF2]")} New Item : ${msg}, ${username}, ${wasDestruction}, ${defindex}`); console.log(`[TF2] New Item :\nMsg:${msg}\nUser:${username}\nDestroy?:${wasDestruction}`);
pan_hook.send({ pan_hook.send({content: "@everyone",embeds: [
content: wasDestruction ? "@everyone" : "", embeds: [ {
{ description: msg,
description: `<:Alert:1151242961485562008> ${msg}`, color: wasDestruction?Discord.Colors.Red:Discord.Colors.Gold
color: wasDestruction ? 0xff0000 : 0xF1C40F }
} ]})
]
})
}) })
tf2.on("displayNotification", (title, body) => { tf2.on("displayNotification", (title, body) => {
console.log(`${colors.yellow("[TF2]")} New Notif: ${title}: ${body}`) console.log(`[TF2] New Notif: ${title}: ${body}`)
ring_hook.send({ ring_hook.send({embeds: [
embeds: [ {
{ description: body,
description: `<:Alert:1151242961485562008> ${body}`, color: Discord.Colors.Gold
color: 0xF1C40F }
} ]})
]
})
}) })
bot.on("ready", () => { bot.on("ready", () => {
console.log(`${colors.blue("[Discord]")} Logged in as ${bot.user.tag}`); console.log(`[Discord] Logged in as ${bot.user.tag}`);
bot.user.setPresence({ activities: [{ name: 'I am cool', type: 4 }], status: 'idle' });
console.log(`${colors.cyan("[Steam]")} Logging into steam`);
user.logOn(config.steam);
}) })
bot.on("messageCreate", (msg) => { bot.on("messageCreate", (msg) => {
if (!msg.webhookId) return; if(msg.author.bot) return;
msg.crosspost(); if (config.discord.channels.includes(msg.channel.id)) {
msg.crosspost();
}
}) })
const sendTestNotifications = () => {
// emit the notifications
tf2.emit("systemMessage", "Test Notification");
tf2.emit("itemBroadcast", "Test Notification", "Test User", false, 0);
tf2.emit("displayNotification", "Test Notification", "Test Notification");
}
// Catch all errors // Catch all errors
process.on('uncaughtException', async (err) => { process.on('uncaughtException', async (err) => {
await sendLog(`${colors.red("[ERROR]")} Uncaught Exception: ${err}`); await sendLog(`${colors.red("[ERROR]")} Uncaught Exception: ${err}`);
@ -122,22 +98,22 @@ process.on('unhandledRejection', async (err) => {
// Handle SIGINT gracefully // Handle SIGINT gracefully
process.on('SIGINT', async () => { process.on('SIGINT', () => {
setTimeout(() => { setTimeout(() => {
console.log(`${colors.red("[ERROR]")} Took too long to exit, exiting forcefully...`); console.log(`${colors.red("[ERROR]")} Took too long to exit, exiting forcefully...`);
process.exit(1); process.exit(1);
}, 10000) }, 10000)
await console.log(`${colors.cyan("[INFO]")} Stop received, exiting...`); console.log(`${colors.blue("[INFO]")} Stop received, exiting...`);
await user.gamesPlayed([]); bot.destroy();
await user.logOff(); user.logOff();
await bot.destroy(); console.log(`${colors.blue("[INFO]")} Goodbye!`);
await console.log(`${colors.cyan("[INFO]")} Goodbye!`);
process.exit(0); process.exit(0);
}); });
console.log(`${colors.cyan("[INFO]")} Starting...`) console.log(`${colors.cyan("[INFO]")} Starting...`)
// Start timer to see how long startup takes // Start timer to see how long startup takes
const initTime = Date.now() const initTime = Date.now()
console.log(`${colors.cyan("[Steam]")} Logging into steam`);
bot.login(config.discord.token); user.logOn(config.steam);
console.log(`${colors.cyan("[Discord]")} Logging into discord`);
bot.login(config.discord.token);