Skip to content

Commit

Permalink
Add stats and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
niksudan committed Feb 24, 2020
1 parent 5d6d1f5 commit 30db5a2
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TOKEN=
AUTHOR_ID=
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "butt",
"version": "1.1.1",
"version": "1.2.0",
"dependencies": {
"discord.js": "^11.5.1",
"dotenv": "^4.0.0",
Expand Down
86 changes: 83 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as Discord from 'discord.js';
import * as randomInt from 'random-int';
import * as times from 'lodash.times';

const info = require('../package.json');

require('dotenv').config();

const FART_REGEX = /\b(((bu(tt|m)|arse|poo(p((er)|y)?)?|shite?|booty)(hole|head)?|buttock|fart|crap|parp|rectum|derriere|sphincter|bottom|rear|rump|behind|dung|excre(te|ment))s?|(ass|gas|anus|tush)(es)?|assholes?|anal|glute(s|us maximus))\b/i;
Expand All @@ -26,7 +28,7 @@ class Butt {
fart(message: Discord.Message) {
if (message.content.match(FART_REGEX)) {
let response = '';
FART_CHARS.forEach((char) => {
FART_CHARS.forEach(char => {
times(randomInt(FART_CHAR_LENGTH) + 1, () => {
response += char;
});
Expand All @@ -47,7 +49,7 @@ class Butt {
this.reply(message, `I think you mean to say "${response}"`);
}
}

/**
* Quote everyone's favourite song
*/
Expand Down Expand Up @@ -91,6 +93,60 @@ class Butt {
}
}

/**
* Poop out stats
*/
stats(message: Discord.Message) {
if (
message.author.id === process.env.AUTHOR_ID &&
message.content === 'buttstats'
) {
const allGuilds = this.client.guilds.filter(guild => guild.available);

message.reply(
`:peach: **butt v${info.version}**\nMember of ${
allGuilds.size
} servers\nFarting at ${allGuilds
.map(guild => guild.memberCount)
.reduce((total, value) => value + total, 0)} members\n\n`,
);

const getServerInfo = async (
guilds: Discord.Collection<string, Discord.Guild>,
) => {
let text = '';
for (let i = 0; i < 5; i += 1) {
text += this.guildToString(guilds.array()[i]);
}
return text;
};

message.reply(
`\n:trophy: **Top Servers**\n${getServerInfo(
allGuilds.sort((a, b) => b.memberCount - a.memberCount),
)}`,
);

message.reply(
`\n:baby: **Recent Servers**\n${getServerInfo(
allGuilds.sort((a, b) => b.joinedTimestamp - a.joinedTimestamp),
)}`,
);
}
}

/**
* Convert a guild into a readable format
*/
guildToString(guild: Discord.Guild) {
let text = '';
text += `__${guild.name}__ (${guild.memberCount} members)\n`;
text += `Based in ${guild.region}\n`;
text += `Member since ${guild.joinedAt.getDate()}/${guild.joinedAt.getMonth() +
1}/${guild.joinedAt.getFullYear()}\n`;
return text;
}

/**
* Be a butt to people
*/
Expand All @@ -99,16 +155,40 @@ class Butt {
this.client.on('ready', () => {
console.log("it's butt time");
});
this.client.on('message', (message) => {

this.client.on('message', message => {
if (!message.author.bot) {
this.didReply = false;
this.stats(message);
this.help(message);
this.samwell(message);
this.cloudToButt(message);
this.fart(message);
this.react(message);
}
});

// Log invites
this.client.on('guildCreate', guild => {
this.client.fetchUser(process.env.AUTHOR_ID).then(author => {
author.sendMessage(
`:peach: **Added To Server!**\nIt's about to get smelly\n${this.guildToString(
guild,
)}`,
);
});
});

// Log removals/bans
this.client.on('guildDelete', guild => {
this.client.fetchUser(process.env.AUTHOR_ID).then(author => {
author.sendMessage(
`:cry: **Removed From Server**\nI've been relieved of gas... permanently\n${this.guildToString(
guild,
)}`,
);
});
});
}
}

Expand Down
120 changes: 120 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@types/node@^12.12.6":
version "12.12.28"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.28.tgz#3a2b5f8d21f96ace690a8832ae9779114612575f"
integrity sha512-g73GJYJDXgf0jqg+P9S8h2acWbDXNkoCX8DLtJVu7Fkn788pzQ/oJsrdJz/2JejRf/SjfZaAhsw+3nd1D5EWGg==

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

async-limiter@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

discord.js@^11.5.1:
version "11.5.1"
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-11.5.1.tgz#910fb9f6410328581093e044cafb661783a4d9e8"
integrity sha512-tGhV5xaZXE3Z+4uXJb3hYM6gQ1NmnSxp9PClcsSAYFVRzH6AJH74040mO3afPDMWEAlj8XsoPXXTJHTxesqcGw==
dependencies:
long "^4.0.0"
prism-media "^0.0.3"
snekfetch "^3.6.4"
tweetnacl "^1.0.0"
ws "^6.0.0"

dotenv@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"
integrity sha1-hk7xN5rO1Vzm+V3r7NzhefegzR0=

lodash.times@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.times/-/lodash.times-4.3.2.tgz#3e1f2565c431754d54ab57f2ed1741939285ca1d"
integrity sha1-Ph8lZcQxdU1Uq1fy7RdBk5KFyh0=

long@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

prism-media@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-0.0.3.tgz#8842d4fae804f099d3b48a9a38e3c2bab6f4855b"
integrity sha512-c9KkNifSMU/iXT8FFTaBwBMr+rdVcN+H/uNv1o+CuFeTThNZNTOrQ+RgXA1yL/DeLk098duAeRPP3QNPNbhxYQ==

random-int@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/random-int/-/random-int-1.0.0.tgz#e6a2ed3448ac9c6646a0657443b1c1521592ed08"
integrity sha1-5qLtNEisnGZGoGV0Q7HBUhWS7Qg=

snekfetch@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/snekfetch/-/snekfetch-3.6.4.tgz#d13e80a616d892f3d38daae4289f4d258a645120"
integrity sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==

source-map-support@^0.5.6:
version "0.5.16"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

ts-node@^8.3.0:
version "8.6.2"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.6.2.tgz#7419a01391a818fbafa6f826a33c1a13e9464e35"
integrity sha512-4mZEbofxGqLL2RImpe3zMJukvEvcO1XP8bj8ozBPySdCUXEcU5cIRwR0aM3R+VoZq7iXc8N86NC0FspGRqP4gg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.6"
yn "3.1.1"

tweetnacl@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==

typescript@^3.5.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.2.tgz#91d6868aaead7da74f493c553aeff76c0c0b1d5a"
integrity sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ==

ws@^6.0.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==
dependencies:
async-limiter "~1.0.0"

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

0 comments on commit 30db5a2

Please sign in to comment.