Skip to content

Instantly share code, notes, and snippets.

@emiflake
Last active April 25, 2017 18:02
Show Gist options
  • Save emiflake/6a190e6d02a986e6fb9f9f96495c9f59 to your computer and use it in GitHub Desktop.
Save emiflake/6a190e6d02a986e6fb9f9f96495c9f59 to your computer and use it in GitHub Desktop.
I See Everything
import Discord = require("discord.js")
import fs = require("fs");
import path = require("path");
namespace ISeeEverything {
enum LogType {
MESSAGE_SENT,
MESSAGE_EDITED,
MESSAGE_DELETED,
USER_JOINED,
USER_LEFT,
ERROR,
WARN,
TYPING_START,
TYPING_STOP,
USERNAME_CHANGE,
PRESENCE_CHANGE,
}
interface LogItem {
type: LogType,
description: string,
timeframe: number
}
function log(logItem: LogItem, filePath = path.join(__dirname, "client.log")): void {
fs.appendFile(filePath, `\n${logItem.type.toString()} -- ${logItem.timeframe} -- ${logItem.description}`, (err) => {
if (err) console.error(err);
});
}
export function start(token: string): void {
let client = new Discord.Client();
client.on("message", msg => {
let logItem: LogItem = {
type: LogType.MESSAGE_SENT,
description: `${msg.author.username} sent '${msg.cleanContent}' in ${msg.channel.id}`,
timeframe: msg.createdTimestamp
}
log(logItem);
});
client.on("messageUpdate", (oldMsg, newMsg) => {
if (oldMsg.content != newMsg.content) {
let logItem: LogItem = {
type: LogType.MESSAGE_EDITED,
description: `${oldMsg.author.username} edited message ${oldMsg.cleanContent} to ${newMsg.cleanContent} in ${oldMsg.channel.id}`,
timeframe: new Date().valueOf()
}
log(logItem);
}
});
client.on("messageDelete", msg => {
let logItem: LogItem = {
type: LogType.MESSAGE_DELETED,
description: `${msg.author.username} deleted message ${msg.cleanContent}`,
timeframe: msg.createdTimestamp
}
log(logItem);
});
client.on("guildMemberAdd", (member: Discord.GuildMember) => {
let logItem: LogItem = {
type: LogType.USER_JOINED,
description: `${member.user.username} has joined ${member.guild.name}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
client.on("error", (error) => {
let logItem: LogItem = {
type: LogType.ERROR,
description: `${error.name} ${error.message}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
client.on("warn", (warn) => {
let logItem: LogItem = {
type: LogType.WARN,
description: `warning: ${warn}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
/* Ultra log only
client.on("typingStart", (channel, user) => {
let logItem: LogItem = {
type: LogType.TYPING_START,
description: `${user.username} has started typing in ${channel.id}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
client.on("typingStop", (channel, user) => {
let logItem: LogItem = {
type: LogType.TYPING_STOP,
description: `${user.username} has stopped typing in ${channel.id}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
*/
client.on("userUpdate", (oldUser, newUser) => {
if (oldUser.username != newUser.username) {
let logItem: LogItem = {
type: LogType.USERNAME_CHANGE,
description: `${oldUser.username} has changed their username to ${newUser.username}`,
timeframe: new Date().valueOf()
}
log(logItem);
}
// TODO: implement more changes
});
client.on("guildMemberRemove", (member: Discord.GuildMember) => {
let logItem: LogItem = {
type: LogType.USER_LEFT,
description: `${member.user.username} has left ${member.guild.name}`,
timeframe: new Date().valueOf()
}
log(logItem);
});
client.on
client.login(token);
}
}
const TOKEN = "your token here";
ISeeEverything.start(TOKEN);
@emiflake
Copy link
Author

To run, compile using typescript: tsc iceverything.ts and run whatever comes out of that shit 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment