Created
December 31, 2016 03:09
-
-
Save haicat/2157e892ee7e6a730bf0034ca54ec60f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://discordapp.com/oauth2/authorize?client_id=172477853672144896&scope=bot&permissions=0 | |
| String.prototype.contains = function(e){return this.indexOf(e)>-1;}; | |
| const http = require("http"); | |
| const fs = require("fs"); | |
| const dp = require("./prompt.js"); | |
| const discord = require("discord.js"); | |
| var ready = require("./readyup.js"); | |
| var url = require('url'); | |
| var path = require('path'); | |
| const client = new discord.Client(); | |
| const prompte = new dp.env(client); | |
| var log = function(msg){console.log(msg);}; | |
| var commands = {}; | |
| var manual = {}; | |
| function readyup(){ | |
| setInterval(routine, 3600000); | |
| log("Initialization complete."); | |
| } | |
| ready.init(readyup); | |
| ready.wait(); | |
| fs.readFile("./prompt_list.js", "utf8", function (err, data){ | |
| if (err) { | |
| log(err.message); | |
| process.exit(); | |
| } | |
| prompte.list = JSON.parse(data); | |
| for (i in prompte.list){ | |
| prompte.list[i] = prompte.toprompt(prompte.list[i]); | |
| } | |
| ready.done(); | |
| }); | |
| ready.wait(); | |
| fs.readFile("./assigned_prompt_list.js", "utf8", function (err, data){ | |
| if (err) { | |
| log(err.message); | |
| process.exit(); | |
| } | |
| prompte.assigned = JSON.parse(data); | |
| for (i in prompte.assigned){ | |
| prompte.assigned[i] = prompte.toprompt(prompte.assigned[i]); | |
| } | |
| ready.done(); | |
| }); | |
| ready.wait(); | |
| client.on('ready', () => { | |
| //log('Ready.'); | |
| ready.done() | |
| }); | |
| client.on('message', message => { | |
| if (message.content[0] == '%') { | |
| var args = message.content.split(" "); | |
| var cmd = args[0].substring(1).toLowerCase(); | |
| var input = message.content.slice(cmd.length + 1).trim(); | |
| if(commands[cmd] != undefined) { | |
| commands[cmd](args, message, input); | |
| } | |
| } | |
| if (message.content[0] == '\\') { | |
| var cmd = message.content.substring(1).toLowerCase(); | |
| if (cmd.contains("/")){return;}; | |
| if (cmd.contains(".")){return;}; | |
| if (cmd.contains("\\")){return;}; | |
| if (cmd.contains(":")){return;}; | |
| if(fs.existsSync("./reaction/" + cmd + ".png")){ | |
| message.channel.sendFile("./reaction/" + cmd + ".png"); | |
| return; | |
| } | |
| if(fs.existsSync("./reaction/" + cmd + ".jpg")){ | |
| message.channel.sendFile("./reaction/" + cmd + ".jpg"); | |
| return; | |
| } | |
| } | |
| }); | |
| commands = { | |
| ping : function (a,m){ | |
| m.channel.sendMessage("PONG!"); | |
| }, | |
| echo : function(a, m, inp){ | |
| m.channel.sendMessage(/*m.content.substring(5)*/ inp); | |
| m.delete(); | |
| }, | |
| prompt : function (a,m){ | |
| var p = prompte.get(m.author.id); | |
| if(p == undefined){ | |
| m.channel.sendMessage("There are no draw prompts left!"); | |
| return; | |
| } | |
| p.str(function(a){ | |
| m.channel.sendMessage("*DRAW:*\n" + a); | |
| }); | |
| }, | |
| draw : function(a,m,inp){ | |
| var t = inp;//m.content.substring(5); | |
| var p = new prompte.prompt(t, m.author.id); | |
| prompte.add(p); | |
| m.channel.sendMessage("Prompt added!"); | |
| }, | |
| discard : function(a,m){ | |
| prompte.discard(m.author.id); | |
| m.channel.sendMessage("Prompt discarded."); | |
| }, | |
| skip : function(a,m){ | |
| commands.discard(a,m); | |
| commands.prompt(a,m); | |
| }, | |
| exec : function(a,m,inp){ | |
| if(m.author.id != 97768885360545792){ | |
| m.reply("nigga fuck off"); | |
| return; | |
| } | |
| var ret; | |
| try{ | |
| ret = eval(/*m.content.substring(5)*/ inp); | |
| }catch(e){ | |
| m.channel.sendMessage("Error:\n"+e.message); | |
| } | |
| ret = String(ret); | |
| if(ret == ""){ret = "\"\"";}; | |
| m.channel.sendMessage(ret); | |
| }, | |
| "%" : function(a,m,inp){ | |
| commands.exec(a,m,inp); | |
| }, | |
| save : function(a,m){ | |
| savePrompt(); | |
| }, | |
| snoop : function(a,m){ | |
| if(a[1] == undefined || a[1] == ""){ | |
| m.channel.sendFile("./snoop.jpg"); | |
| return; | |
| } | |
| m.channel.fetchMessage(a[1]) | |
| .then(function(message){ | |
| if(message.author.id == 97768885360545792){ | |
| m.channel.sendFile("./snoop.jpg"); | |
| return; | |
| } | |
| var tt = "I found **" + message._edits.length + "** past versions for that message." | |
| tt += "\n**Current:**\n" + message.content + "\n**Past versions:**"; | |
| for (var i = 0; i < message._edits.length; i++){ | |
| tt += "\n" + message._edits[i].content; | |
| } | |
| m.channel.sendMessage(tt); | |
| }) | |
| .catch(err => m.channel.sendMessage("Error:\n"+err.message)); | |
| }, | |
| help : function(a,m){ | |
| if(a[1] == undefined || a[1] == ""){ | |
| var msg = ".\n"+ | |
| "**Help Manual**\n"+ | |
| "To view a specific manual article use `%help (page name)` (without parentheseis).\n"+ | |
| "Usages are given as: `%command (required argument) [optional argument]`\n\n"+ | |
| "**Available manual pages**\n"+ | |
| "(Commands are listed in `code blocks`, non-command pages are *italic*)\n"; | |
| for (i in manual) { | |
| if(manual[i].nocmd == true){ | |
| msg += "*" + i + "* "; | |
| continue; | |
| } | |
| msg += "`" + i + "` "; | |
| } | |
| m.channel.sendMessage(msg); | |
| return; | |
| } | |
| var page = a[1].trim().toLowerCase(); | |
| if(manual[page] == undefined) { | |
| m.channel.sendMessage("Sorry, I couldnt find that page in the manual!"); | |
| return; | |
| } | |
| pp = manual[page]; | |
| var usg = ""; | |
| var aka = ""; | |
| if (pp.usage != undefined && pp.usage != ""){ | |
| usg = "\n**Usage:**\n`%" + page + " " + pp.usage + "`"; | |
| } | |
| if (pp.aka != undefined){ | |
| aka = "\n**Aliases:**\n"; | |
| for (var i = 0; i < pp.aka.length; i++) { | |
| aka += "`" + pp.aka[i] + "` "; | |
| } | |
| } | |
| m.channel.sendMessage(pp.desc + usg + aka); | |
| }, | |
| "?" : function(a,m){ | |
| commands.help(a,m); | |
| }, | |
| setlog : function(a,m){ | |
| if(m.author.id != 97768885360545792){ | |
| m.reply("You do not have permission to use this command!"); | |
| return; | |
| } | |
| log = function(msg){ | |
| log.channel.sendMessage(msg); | |
| }; | |
| log.channel = m.channel;//client.channels.array()[m.id]; | |
| //log.id = m.id; | |
| log("Log channel set."); | |
| } | |
| }; | |
| manual = { | |
| ping : { | |
| desc : "Test me by having me send a quick response." | |
| }, | |
| echo : { | |
| desc : "Have me repeat whatever you say.", | |
| usage : "(message to repeat)" | |
| }, | |
| prompt : { | |
| desc : "See `%help dod` for more info." | |
| }, | |
| draw : { | |
| desc : "See `%help dod` for more info.", | |
| usage : "(drawing prompt)" | |
| }, | |
| discard : { | |
| desc : "See `%help dod` for more info." | |
| }, | |
| skip : { | |
| desc : "See `%help dod` for more info." | |
| }, | |
| snoop : { | |
| desc : "See the past edit versions of a message.", | |
| usage : "(message id)" | |
| }, | |
| help : { | |
| desc : "View the manual.", | |
| usage : "[page name]", | |
| aka : ["?"] | |
| }, | |
| dod : { | |
| nocmd : true, | |
| desc : ".\n**Doodle or Die**\n" + | |
| "To fetch a random drawing prompt from the pool, use `%prompt`.\n" + | |
| "This prompt will be then assigned to you. While it is assigned to you, I will not give it to anyone else.\n" + | |
| "If you decide you don't want to draw the prompt that I give you, you can put it back in the pool with `%discard`.\n" + | |
| "While you have a prompt assigned to you, you can re-check what it was simply by typing `%prompt` again." + | |
| " It will not assign you a new one unless you `%discard` your old one first.\n" + | |
| "To discard and get a new prompt quickly as one command, type `%skip`.\n" + | |
| "To add a drawing prompt to the pool, use `%draw`. (see `%help draw` for usage)" | |
| } | |
| }; | |
| client.login('{LOGIN ID}'); | |
| function savePrompt(){ | |
| try{ | |
| log("Saving prompts."); | |
| var str = JSON.stringify(prompte.list); | |
| fs.writeFile("./prompt_list.js", str, function(err){ | |
| if(err){ | |
| log("Error:\n"+err.message); | |
| }else{ | |
| var str2 = JSON.stringify(prompte.assigned); | |
| fs.writeFile("./assigned_prompt_list.js", str2, function(err2){ | |
| if(err2){ | |
| log("Error:\n"+err2.message); | |
| }else{ | |
| log("Save Complete."); | |
| } | |
| }); | |
| } | |
| }); | |
| }catch(e){ | |
| log("Error:\n"+e.message); | |
| } | |
| }; | |
| function routine(){ | |
| log("----"+Date()+"----"); | |
| savePrompt(); | |
| } | |
| ready.finish(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment