Permalink
Browse files

add: datadog, new tags for CC and general things

  • Loading branch information...
AdityaTD committed Oct 18, 2018
1 parent 280929f commit a862816c6a563afc9382e99cb483872d9e5c8000
@@ -1,5 +1,11 @@
const { Event } = require("klasa");
const { Parser } = require("breadtags");
const files = require("fs").readdirSync(`${process.cwd()}/lib/tags`);
for (const file of files) {
if (file.includes("index")) continue;
Parser.loadTag(require(`${process.cwd()}/lib/tags/${file}`));
}
module.exports = class extends Event {
@@ -20,7 +26,7 @@ module.exports = class extends Event {
}
async init() {
this.parser = new Parser();
this.parser = new Parser({ throwErrors: true });
}
};
@@ -3,6 +3,7 @@ const { Event } = require("klasa");
module.exports = class extends Event {
async run(guild) {
this.client.datadog.increment("pengubot.guildsadded");
// Patreon Checker
if (this.client.config.main.patreon === true && this.client.user.id === "438049470094114816") {
if (!this.client.settings.pGuilds.includes(guild.id)) {
@@ -0,0 +1,9 @@
const { Event } = require("klasa");
module.exports = class extends Event {
async run() {
this.client.datadog.increment("pengubot.guildsremoved");
}
};
@@ -2,6 +2,8 @@ const { Client } = require("klasa");
const { Client: IdioticAPI } = require("idiotic-api");
const { WebhookClient } = require("discord.js");
const config = require("../../config");
const { StatsD } = require("hot-shots");
const dogstats = new StatsD("localhost", 8125);
// Custom
const permissionLevels = require(`./permissionLevels`);
@@ -48,6 +50,7 @@ class PenguClient extends Client {
this.rawEvents = new RawEventStore(this);
this.registerStore(this.rawEvents);
this.emotes = { check: "<:penguSuccess:435712876506775553>", cross: "<:penguError:435712890884849664>", loading: "<a:penguLoad:435712860744581120>" };
this.dogstats = dogstats;
}
}
@@ -0,0 +1,26 @@
const { Builder } = require("breadtags");
const { get } = require("snekfetch");
module.exports = new Builder()
.setDescription("Get JSON content from a websource.")
.setType("getjson")
.hasAction()
.requiredArgs(1)
.setProcess(async ctx => {
const [str, propPath] = ctx.value;
const { body } = await get(str);
if (!body || body instanceof Buffer) throw "Malformed JSON.";
if (!propPath) return JSON.stringify(body);
return getProp(body, propPath);
});
function getProp(body, prop) {
if (prop === undefined) return body;
const propParts = `${prop}`.split(".");
let result = body, lastProp;
while ((lastProp = propParts.shift()) !== undefined) {
if (result[lastProp] === undefined) return undefined;
result = result[lastProp];
}
return result;
}
@@ -0,0 +1,21 @@
const { Builder } = require("breadtags");
const { Argument } = require("klasa");
module.exports = new Builder()
.setDescription("Sends a message to the provided channel.")
.setType(["sendchannel", "channelsend"])
.hasAction()
.requiredArgs(1)
.setProcess(ctx => {
const [id, message] = ctx.value;
if (!id || !message) throw "You must provide a valid channel ID and content.";
let channel;
if (Argument.regex.channel.test(id)) {
channel = ctx.guild.channels.get(id);
} else {
channel = ctx.guild.channels.find(chan => chan.name === id);
}
if (!channel || channel.type === "voice") throw "An invalid channel or channel type was specified.";
if (!channel.postable) throw "I do not have permissions to send messages to that channel.";
return channel.sendMessage(message);
});
@@ -37,6 +37,7 @@
"erlpack": "github:discordapp/erlpack",
"google-translate-api": "^2.3.0",
"heapdump": "^0.3.9",
"hot-shots": "^5.9.1",
"idiotic-api": "github:YorkAARGH/Idiotic-Wrapper",
"klasa": "github:dirigeants/klasa",
"klasa-dashboard-hooks": "github:PenguBot/klasa-dashboard-hooks",
@@ -0,0 +1,20 @@
const { Route } = require("klasa-dashboard-hooks");
module.exports = class extends Route {
constructor(...args) {
super(...args, { route: "patreonhook" });
}
/* Test File - Patreon Hooks Incoming? :O */
async post(request, response) {
const body = request.read();
console.log(body);
response.statusCode(200);
return response.end();
}
};
@@ -0,0 +1,29 @@
const { Task } = require("klasa");
module.exports = class MemorySweeper extends Task {
async run() {
let [users, guilds, vc] = [0, 0, 0];
const results = await this.client.shard.broadcastEval(`[this.guilds.reduce((prev, val) => val.memberCount + prev, 0), this.guilds.size, this.lavalink.map(u => u).filter(p => p.playing).length]`);
for (const result of results) {
users += result[0];
guilds += result[1];
vc = +result[3];
}
this.client.dogstats.gauge("pengubots.totalcommands", this.client.configs.counter.total);
this.client.dogstats.gauge("pengubot.users", users);
this.client.dogstats.gauge("pengubot.guilds", guilds);
this.client.dogstats.gauge("pengubots.voicestreams", vc);
return;
}
async init() {
if (this.client.user.id !== "303181184718995457") return this.disable();
if (!this.client.configs.schedules.some(schedule => schedule.taskName === this.name)) {
await this.client.schedule.create("datadog", "*/1 * * * *");
}
}
};

0 comments on commit a862816

Please sign in to comment.