Reformat and move things around a bit
This commit is contained in:
parent
7c20c269cd
commit
0e5781ca6d
77
index.js
77
index.js
|
@ -6,34 +6,13 @@ 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 { 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 });
|
||||||
let user = new SteamUser();
|
let user = new SteamUser();
|
||||||
let tf2 = new TeamFortress2(user);
|
let tf2 = new TeamFortress2(user);
|
||||||
// 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) => {
|
|
||||||
console.log(`${colors.green("[Lang]")} Got TF2 Lang File from wiki`);
|
|
||||||
// set lang from body
|
|
||||||
tf2.setLang(res.data)
|
|
||||||
// Save a local copy
|
|
||||||
fs.writeFileSync("./tf_english.txt", res.data);
|
|
||||||
console.log(`${colors.green("[Lang]")} Saved backup TF2 Lang File`);
|
|
||||||
if (tf2.lang) return console.log(`${colors.yellow("[TF2]")} Loaded TF2 Lang File`);
|
|
||||||
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
|
||||||
}).catch((err) => {
|
|
||||||
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File from wiki, trying local file`);
|
|
||||||
// try to load local file
|
|
||||||
try {
|
|
||||||
tf2.setLang(fs.readFileSync("./tf_english.txt", "utf8"));
|
|
||||||
if (tf2.lang) return console.log(`${colors.yellow("[TF2]")} Loaded TF2 Lang File`);
|
|
||||||
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
user.logOn(config.steam);
|
user.logOn(config.steam);
|
||||||
|
|
||||||
user.on("loggedOn", async (stuff) => {
|
user.on("loggedOn", async (stuff) => {
|
||||||
|
@ -45,6 +24,28 @@ user.on("loggedOn", async (stuff) => {
|
||||||
|
|
||||||
tf2.on("connectedToGC", async (ver) => {
|
tf2.on("connectedToGC", async (ver) => {
|
||||||
console.log(`${colors.yellow("[TF2]")} Connected to GC, version: ${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) => {
|
||||||
|
console.log(`${colors.green("[Lang]")} Got TF2 Lang File from wiki`);
|
||||||
|
// set lang from body
|
||||||
|
tf2.setLang(res.data)
|
||||||
|
// Save a local copy
|
||||||
|
fs.writeFileSync("./tf_english.txt", res.data);
|
||||||
|
console.log(`${colors.green("[Lang]")} Saved backup TF2 Lang File`);
|
||||||
|
if (tf2.lang) return console.log(`${colors.yellow("[TF2]")} Loaded TF2 Lang File`);
|
||||||
|
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File from wiki, trying local file`);
|
||||||
|
// try to load local file
|
||||||
|
try {
|
||||||
|
tf2.setLang(fs.readFileSync("./tf_english.txt", "utf8"));
|
||||||
|
if (tf2.lang) return console.log(`${colors.yellow("[TF2]")} Loaded TF2 Lang File`);
|
||||||
|
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`${colors.green("[Lang]")} Failed to load TF2 Lang File`);
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tf2.on("disconnectedFromGC", (reason) => {
|
tf2.on("disconnectedFromGC", (reason) => {
|
||||||
|
@ -53,32 +54,38 @@ tf2.on("disconnectedFromGC", (reason) => {
|
||||||
|
|
||||||
tf2.on("systemMessage", (msg) => {
|
tf2.on("systemMessage", (msg) => {
|
||||||
console.log(`${colors.yellow("[TF2]")} New System Message: ${msg}`)
|
console.log(`${colors.yellow("[TF2]")} New System Message: ${msg}`)
|
||||||
notif_hook.send({embeds: [
|
notif_hook.send({
|
||||||
|
embeds: [
|
||||||
{
|
{
|
||||||
description: `<:Messages:1151242960655089744> ${msg}`,
|
description: `<:Messages:1151242960655089744> ${msg}`,
|
||||||
color: 0x3498DB
|
color: 0x3498DB
|
||||||
}
|
}
|
||||||
]})
|
]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tf2.on("itemBroadcast", (msg, username, wasDestruction, defindex) => {
|
tf2.on("itemBroadcast", (msg, username, wasDestruction, defindex) => {
|
||||||
console.log(`${colors.yellow("[TF2]")} New Item :$ {msg}`);
|
console.log(`${colors.yellow("[TF2]")} New Item :$ {msg}`);
|
||||||
pan_hook.send({content: wasDestruction?"@everyone":"",embeds: [
|
pan_hook.send({
|
||||||
|
content: wasDestruction ? "@everyone" : "", embeds: [
|
||||||
{
|
{
|
||||||
description: `<:Alert:1151242961485562008> ${msg}`,
|
description: `<:Alert:1151242961485562008> ${msg}`,
|
||||||
color: wasDestruction?0xff0000:0xF1C40F
|
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(`${colors.yellow("[TF2]")} New Notif: ${title}: ${body}`)
|
||||||
ring_hook.send({embeds: [
|
ring_hook.send({
|
||||||
|
embeds: [
|
||||||
{
|
{
|
||||||
description: `<:Alert:1151242961485562008> ${body}`,
|
description: `<:Alert:1151242961485562008> ${body}`,
|
||||||
color: 0xF1C40F
|
color: 0xF1C40F
|
||||||
}
|
}
|
||||||
]})
|
]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.on("ready", () => {
|
bot.on("ready", () => {
|
||||||
|
@ -86,10 +93,8 @@ bot.on("ready", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.on("messageCreate", (msg) => {
|
bot.on("messageCreate", (msg) => {
|
||||||
if(msg.author.bot) return;
|
if (!msg.webhookId) return;
|
||||||
if (config.discord.channels.includes(msg.channel.id)) {
|
|
||||||
msg.crosspost();
|
msg.crosspost();
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const sendTestNotifications = () => {
|
const sendTestNotifications = () => {
|
||||||
|
|
Loading…
Reference in a new issue