working discord bot

This commit is contained in:
cameron 2018-06-13 01:12:47 -04:00
commit e85d40cedc
5 changed files with 3422 additions and 0 deletions

View File

@ -0,0 +1,10 @@
module.exports.matches = [ { "!8ball" } ];
function basicRoute(str)
{
if(str.startsWith("!8ball"))
{
}
}

225
main.js Normal file
View File

@ -0,0 +1,225 @@
const Discord = require("discord.js");
const Gamedig = require('gamedig');
const client = new Discord.Client();
const fs = require('fs');
const request = require('request');
const rp = require('request-promise-native');
const striptags = require('striptags');
const glob = require('glob');
const path = require('path');
const twitter = require('twitter');
var pepesList = [];
var markov = require('markov');
var m = markov(2);
const twitterClient = new twitter({
consumer_key: 'd1QtB67GohqcCKSD0GdYF1nkh',
consumer_secret: 'tYkCxEKIahoykUSS71DgWjK7O1IX5BgGLxOSFE7v0uXLGGviCS',
access_token_key: '384120881-IETrcVQHmwWec3jtifY7FhyODRY944ufeEh2pwcT',
access_token_secret: 'EtnE7bggaKOrk0pfxkAkQEb7iLe8yyqYm8M7GulAbbwTt'
});
async function generateTwitterEmbed(tweetData)
{
}
async function getLatestPost(user)
{
//GET https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
try {
let post = await twitterClient.get('statuses/user_timeline', { count: 1, screen_name: user });
console.log(post[0].id_str);
return post[0].id_str;
} catch(e) {
return 'reee';
}
}
//returns a word definition from urban dictionary
async function ud(word)
{
let page = await rp('http://api.urbandictionary.com/v0/define?term=' + word, { json: true });
if ( page.result_type === 'exact' )
{
let defStr = "";
defStr += page.list[0].word + "\n\n" + page.list[0].definition + "\n\n" + "Example: " + page.list[0].example;
console.log("defStr: " + defStr);
return defStr;
} else {
return "No results.";
}
}
function initMarkov()
{
//get stuff from pol
request('https://a.4cdn.org/pol/catalog.json', { json: true },
(err, res, body) => {
if (err) { return console.log(err); }
for(let i = 0; i < body.length; i++)
{
for(let j = 0; j < body[i].threads.length; j++)
{
var post = striptags(body[i].threads[j].com);
post = post.toLowerCase();
m.seed(post);
if(body[i].threads[j].last_replies == undefined) { continue; }
for(let k = 0; k < body[i].threads[j].last_replies.length; k++)
{
var post2 = striptags(body[i].threads[j].last_replies[k].com);
post2 = post2.toLowerCase();
m.seed(post2);
}
}
}
});
}
function loadPepes()
{
fs.readFile('pepes.txt', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
pepesList = data.split("\n");
});
}
//returns a dank pepe
function pepe()
{
let dankPepe = new Discord.RichEmbed();
let selection = Math.floor(Math.random() * (pepesList.length));
dankPepe.setImage(pepesList[selection]);
return dankPepe;
}
function magic8ball()
{
const answers = [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs point to yes',
'Reply hazy try again',
'Ask again later',
'Better not tell you now',
'Cannot predict now',
'Concentrate and ask again',
"Don't count on it",
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful' ];
let selection = Math.floor(Math.random() * (answers.length));
return answers[selection];
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
loadPepes();
});
client.on('message', async (msg) => {
if (msg.content === '!ping') {
msg.reply('Pong!');
} else if (msg.content === '!8ball') {
msg.reply(magic8ball());
} else if (msg.content.startsWith('<@' + client.user.id)) {
if (msg.content.trim().endsWith('?')) {
msg.reply(magic8ball());
}
} else if (msg.content === '!mc') {
Gamedig.query({
type: 'minecraftping',
host: 'americastrong.jumpingcrab.com'
}).then((state) => {
let str = "MINECRAFT SERVER INFO\n";
console.log(state);
str += "Server Name: " + state.raw.description + "\n";
str += "Players: " + state.players.length + "/" + state.maxplayers + "\n";
str += "Currently Online: "
for (let i = 0; i < state.players.length; i++) {
str += state.players[i].name + ", ";
}
str = str.slice(0, -2);
str += "\n";
msg.reply(str);
}).catch((error) => {
msg.reply("Server is offline!");
});
} else if (msg.content === '!gm') {
try {
let gameinfo = await Gamedig.query({type: 'garrysmod',
host: 'construct420.game.nfoservers.com'});
let str = "GARRY'S MOD SERVER INFO\n";
str += "Server name: " + gameinfo.name + "\n";
str += "Current Map: " + gameinfo.map + "\n";
str += "Players: " + gameinfo.players.length + "/" + gameinfo.maxplayers + "\n";
str += "Currently Online: "
for (let i = 0; i < gameinfo.players.length; i++) {
str += gameinfo.players[i].name + ", ";
}
str = str.slice(0, -2);
str += "\n";
str += "Server IP: 192.223.30.22\n"
msg.reply(str);
} catch (err) {
console.log(err);
msg.reply("Server is offline!");
}
} else if (msg.content === '!pepe') {
let chan = msg.channel;
let pepeImg = pepe();
chan.send(pepeImg);
} else if (msg.content.startsWith('!ud')) {
let chan = msg.channel;
let words = msg.content.substring(msg.content.indexOf(" ") + 1);
let def = await ud(words);
console.log(def);
chan.send("```\n" + def + "```");
} else if (msg.content.startsWith('!markov')) {
let msgArray = msg.content.split(" ");
console.log(msgArray);
let chan = msg.channel;
if(msgArray[1] && msgArray[2] != null) {
let msg2 = m.forward([msgArray[1] + '_' + msgArray[2]], 20).join(' ');
chan.send(msgArray[1] + ' ' + msgArray[2] + ' ' + msg2);
} else {
msg.reply("Usage: !markov <word1> <word2>");
}
} else if (msg.content.startsWith('!bsp')) {
let chan = msg.channel;
let postId = await getLatestPost('dot_bsp');
chan.send("https://www.twitter.com/dot_bsp/status/" + postId);
}
});
client.login('MzYyNzU1MzE3MTczNTgzODcy.DK3R1A.8M22ZkNaaoHy-ifBQwVivSU7svY');

1912
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "dank-bot",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"discord.js": "^11.2.1",
"gamedig": "^1.0.37",
"glob": "^7.1.2",
"markov": "0.0.7",
"nodemon": "^1.12.1",
"npm-init": "^1.3.1",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"striptags": "^3.1.0",
"twitter": "^1.7.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

1251
pepes.txt Normal file

File diff suppressed because it is too large Load Diff