This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
forked from dhawton/VBRP.MCP
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
242 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist | ||
config.json | ||
node_modules | ||
node_modules | ||
log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
{ | ||
"discord": { | ||
"token": "", | ||
"announceChannel": "promote-your-content", | ||
"role": "" | ||
"token": "" | ||
}, | ||
"applications": [ | ||
{ | ||
"type": "", | ||
"docId": "", | ||
"sheetId": "", | ||
"announce": { | ||
"column": 0, | ||
"values": { | ||
"term": "channelId" | ||
} | ||
} | ||
} | ||
], | ||
"googleapi": { | ||
|
||
"type": "", | ||
"project_id": "", | ||
"private_key_id": "", | ||
"private_key": "", | ||
"client_email": "", | ||
"client_id": "", | ||
"auth_url": "", | ||
"token_uri": "", | ||
"auth_provider_x509_cert_url": "", | ||
"client_x509_cert_url": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,79 @@ | ||
import googleapi from "./index"; | ||
import csvParser from "csv-parser"; | ||
import toReadableStream from "to-readable-stream"; | ||
import getStream from "get-stream"; | ||
|
||
import { googleapi, guild } from "./index"; | ||
import Log from "./Log"; | ||
import LiveEmbed from "./LiveEmbed"; | ||
import Utils from "./Utils"; | ||
|
||
class ApplicationHandler { | ||
config: Config["applications"]; | ||
config: ApplicationConfig; | ||
intTimer: NodeJS.Timer; | ||
|
||
constructor(config) { | ||
constructor(config: ApplicationConfig) { | ||
this.config = config; | ||
this.intTimer = setInterval(() => { | ||
try { | ||
this.handle(); | ||
} catch (err) { | ||
Log.error(`Error running application handle ${err}`); | ||
} | ||
}, 5 * 60 * 1000); | ||
this.handle(); | ||
} | ||
|
||
async handle(): Promise<void> { | ||
let doc; | ||
try { | ||
doc = await googleapi.loadSheet(this.config.docId, this.config.sheetId); | ||
Log.info(`Caught new log entry for ${this.config.type}: ${Buffer.from(JSON.stringify(doc)).toString("base64")}`); | ||
let streamData = toReadableStream(doc); | ||
let data: any = await getStream.array(streamData.pipe(csvParser({ headers: false }))); | ||
const appquestions = []; | ||
data.forEach((v: string[], idx: number) => { | ||
if (idx === 0) { | ||
Object.keys(v).forEach((key) => { | ||
appquestions.push(v[key]); | ||
}); | ||
} else { | ||
const channel = this.findChannel(v); | ||
if (channel !== null) { | ||
googleapi.deleteRow(idx, this.config.docId, this.config.sheetId); | ||
let msg = LiveEmbed.createFromApplication(this.config.type, appquestions, v); | ||
Utils.sendMessage(guild, channel, `NEW APPLICATION RECEIVED:`, msg); | ||
} | ||
} | ||
}); | ||
} catch (err) { | ||
Log.error(`Error loading sheet: ${err}`); | ||
console.trace(err); | ||
return; | ||
} | ||
} | ||
|
||
findChannel(appdata: string[]): string { | ||
if (typeof this.config.announce === "string") { | ||
return this.config.announce; | ||
} else if (typeof this.config.announce.values === "string") { | ||
return this.config.announce.values; | ||
} else if (typeof this.config.announce === "object") { | ||
let channel: string; | ||
Object.keys(this.config.announce.values).forEach((key) => { | ||
if (appdata[this.config.announce.column].toLowerCase() === key.toLowerCase()) { | ||
channel = this.config.announce.values[key]; | ||
} | ||
}); | ||
|
||
if (channel) { | ||
return channel; | ||
} else if (this.config.announce.values["rest"]) { | ||
return this.config.announce.values["rest"]; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} | ||
|
||
export default ApplicationHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Discord from "discord.js"; | ||
|
||
|
||
class LiveEmbed { | ||
static createFromApplication(apptype: string, appquestions: string[], appdata: string[]): Discord.MessageEmbed { | ||
const msgEmbed = new Discord.MessageEmbed(); | ||
msgEmbed.setColor("#ff0000"); | ||
msgEmbed.setTitle(`APPLICATION TYPE: ${apptype.toUpperCase()}`); | ||
appquestions.forEach((_,idx) => { | ||
msgEmbed.addField(appquestions[idx], appdata[idx], false); | ||
}); | ||
msgEmbed.setFooter("END OF LINE."); | ||
return msgEmbed; | ||
} | ||
} | ||
|
||
export default LiveEmbed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import Discord from "discord.js"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import GoogleAPI from "./google"; | ||
import ApplicationHandler from "./ApplicationHandler"; | ||
import GoogleAPI from "./GoogleAPI"; | ||
|
||
import Log from "./log"; | ||
import Log from "./Log"; | ||
|
||
if (!fs.existsSync(path.resolve(__dirname, "config.json"))) { | ||
if (!fs.existsSync(path.resolve("config.json"))) { | ||
Log.error("Config not found"); | ||
process.exit(1); | ||
} | ||
|
||
const config: Config = JSON.parse(fs.readFileSync(path.resolve(__dirname, "config.json")).toString()); | ||
const config: Config = JSON.parse(fs.readFileSync(path.resolve("config.json")).toString()); | ||
|
||
const client = new Discord.Client(); | ||
const googleapi = new GoogleAPI(config.googleapi); | ||
let guild: Discord.Guild; | ||
googleapi.authentication(); | ||
const applicationhanders = {}; | ||
|
||
Log.info("MASTER CONTROL PROGRAM"); | ||
|
||
client.on("ready", async () => { | ||
Log.info(`Logged in as ${client.user.tag}`); | ||
client.user.setActivity("VBRP Whitelist Apps", { type: "WATCHING" }); | ||
const doc = await googleapi.loadSheet("1cPjVoiO3KvhjmWu_Fc86FWGxUaUYAoyCHxghne6af9A"); | ||
Log.info(JSON.stringify(doc)); | ||
//buildHandlers(googleapi); | ||
guild = client.guilds.cache.first(); | ||
config.applications.forEach((v) => { | ||
applicationhanders[v.type] = new ApplicationHandler(v); | ||
}); | ||
}); | ||
|
||
client.login(config.discord.token); | ||
|
||
export default googleapi; | ||
export { googleapi, guild }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.