Skip to content

Instantly share code, notes, and snippets.

@bitnetwork
Created January 14, 2017 03:55
Show Gist options
  • Save bitnetwork/23f82d573b0792d4a1580e467048052b to your computer and use it in GitHub Desktop.
Save bitnetwork/23f82d573b0792d4a1580e467048052b to your computer and use it in GitHub Desktop.
const lib_discord = require("discord.js");
const readline = require("readline");
var interFace = readline.createInterface({
input: process.stdin,
output: process.stdout
});
interFace.question("Token? ", (token) => {
interFace.close();
var client = new lib_discord.Client();
client.on("ready", () => {
console.log("Selfbot ready!");
});
var poll = {
active: false,
title: "",
options: [],
votes: [],
alreadyVoted: []
};
client.on("message", message => {
if (poll.active === true && parseInt(message.content) > 0 && parseInt(message.content) <= poll.options.length && poll.alreadyVoted.filter(function(user) { return message.author.id === user; }).length === 0) {
poll.votes[parseInt(message.content) - 1]++;
poll.alreadyVoted.push(message.author.id);
}
// ONLY USER MESSAGES BEYOND THIS POINT
var header = message.channel.guild.name + "/" + message.channel.name + ", " + message.author.username + "#" + message.author.discriminator + ": ";
console.log(header + message.content.replace(/\n/g, "\n" + " ".repeat(header.length)));
if (message.author !== client.user) return;
var prefix = "`";
var seperator = " ";
if (!message.content.startsWith(prefix)) return;
var command = message.content.split(" ").length >= 1 ? message.content.split(" ")[0].substring(prefix.length) : "";
var params = message.content.split(seperator).slice(1);
if (command === "purge") {
var messagecount = 100;
if (params.length > 0) {
messagecount = parseInt(params[0]);
}
message.channel.fetchMessages({limit: 100}).then(function(messages) {
var messageArray = messages.array();
messageArray = messageArray.filter(function(m) { return m.author.id === client.user.id; });
messageArray.length = messagecount + 1;
messageArray.map(function(m) { m.delete().catch(console.error); });
});
} else if (command === "stfu") {
setTimeout( function() { message.edit("**QUIET**"); }, 50);
} else if (command === "poll") {
if (poll.active === false) {
var spaceParams = message.content.split(" ").slice(1).join(" ").split(";");
poll.active = true;
poll.title = spaceParams[0];
poll.options = [];
poll.votes = [];
poll.alreadyVoted = [];
var pollText = message.author.username + " is starting a poll.\n\n**" + spaceParams[0] + "**\nType the number of the item that you want.\n";
for (var i=1; i<spaceParams.length; i++) {
pollText += "\n" + i + " - " + spaceParams[i];
poll.options.push(spaceParams[i]);
poll.votes.push(0);
}
setTimeout( function() { message.edit(pollText); }, 50);
} else {
poll.active = false;
var pollText = "**" + poll.title + "**\nPoll results\n";
for (var i=0; i<poll.options.length; i++) {
pollText += "\n" + poll.options[i] + " - " + poll.votes[i] +" votes";
}
setTimeout( function() { message.edit(pollText); }, 50);
}
} else if (command === "pd") {
message.delete();
setTimeout( function() { message.channel.send("!payday") }, 50);
} else if (command === "info") {
} else if (command === ">") {
try {
var result = eval(message.content.substring(prefix.length + 1));
setTimeout( function() { message.channel.send(result); }, 50);
} catch (error) {
setTimeout( function() { message.channel.send(error.message); }, 50);
}
}
});
client.login(token);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment