Last active
March 26, 2018 08:12
-
-
Save fauzandotme/b029c49e633384150d746c446dbba1b4 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
how to setup: | |
1. clone derplib: https://github.com/MakuraYami/derplib | |
2. install dependencies: npm i --save curl-ganteng jsonfile youtube-search | |
3. create file test.js and paste all text in this gist | |
4. create file in modules/MAL.js, paste this content from here: https://gist.github.com/fauzandotme/e1709bb962cb054be6708327af4620b3 | |
4. setup chatango account below | |
5. run: node test.js | |
Note: run this on nodejs version ^6x | |
Silahkan curi, kembangkan, modifikasi, tanpa harus meninggalkan credit. | |
@fauzandotme | |
*/ | |
const tangoUsername = ''; //chatango username | |
const tangoPassword = ''; //chatango password | |
const tangoRoom = ''; //chatango room | |
const youtubeAPIKey = 'AIzaSyATIjlBGIfMdEm_Gf9_J5_Je0b3UH2w0ks'; //your youtube api key | |
const DerpLib = require('./derplib'); | |
const tool = require('curl-ganteng'); | |
const jsonfile = require('jsonfile'); | |
const MAL = require('./modules/MAL.js'); | |
const yts = require('youtube-search'); | |
const ytOpts = { | |
maxResults: 1, | |
key: youtubeAPIKey | |
}; | |
const data = {}; | |
DerpLib.addAccount(tangoUsername, tangoPassword); | |
console.log('[DB] Loading...'); | |
DerpLib.Room({room: tangoRoom, account: tangoUsername}) | |
DerpLib.events.on("request", function(req){ | |
let username = req.message.name.replace(/\#|\_/, ''); | |
let pesan = req.message.text; | |
if(/@fauzan|@mynameiszan/g.test(pesan)) { | |
req.room.message(`@${username} Yang punya akun udah pensiun, kalau penting hubungi lewat telegram: https://t.me/fauzan_js | autoreply`); | |
} | |
if(reply_if(username)) { | |
let cmd = filter_command(pesan); | |
if(cmd) { | |
if(cmd.command == 'yt') { | |
yts(cmd.keyword, ytOpts, (err, done) => { | |
if(err) req.room.message(`somethinig error while searching youtube videos`) | |
let reply = `${done[0].title}\n${done[0].link}`; | |
req.room.message(reply); | |
}); | |
} else if(cmd.command == 'mal') { | |
MAL.search(cmd.keyword).then((done) => { | |
let reply = 'Silahkan pilih:\n'; | |
done.suggestions.map((item, index) => { | |
reply += `${index+1} : ${item.value}\n`; | |
}) | |
if(cmd.choose) { | |
return MAL.scrap(done.suggestions[cmd.choose -1].data).then((done) => { | |
let out = parseMAL(done); | |
if(out.length > 2500) { | |
let out2 = out.match(/.[\s\S]{1,2900}/gm); | |
out2.forEach(elem => { | |
req.room.message(elem); | |
}); | |
} else { | |
req.room.message(out); | |
} | |
}) | |
} else { | |
req.room.message(reply); | |
} | |
}) | |
} else if (cmd.command == 'rank') { | |
let admins = get_admin(); | |
req.room.message(admins); | |
} else if (cmd.command == 's') { | |
tool.curl(`http://nanime.in/api/search?s=${urlEncode(cmd.keyword)}`).then((done) => { | |
let response = true; | |
try { | |
response = JSON.parse(done.body); | |
} catch (e) { | |
response = {error: 1, message: 'something error'}; | |
} | |
if(response.error) return req.room.message(response.message); | |
let out = `Search result ${cmd.keyword}:\n`; | |
response.result.map((item, index) => { | |
out += `${index + 1} ${item.title} http://nanime.in/${item.type}/${item.slug}\n` | |
}) | |
if(out.length > 2500) { | |
let out2 = out.match(/.[\s\S]{1,2900}/gm); | |
out2.forEach(elem => { | |
req.room.message(elem); | |
}); | |
} else { | |
req.room.message(out); | |
} | |
}) | |
} else if (cmd.command == 'mod') { | |
if(is_admin(username)) { | |
let admins = jsonfile.readFileSync(`./admins.json`); | |
admins.moderator.push(cmd.keyword); | |
jsonfile.writeFileSync(`./admins.json`, admins); | |
req.room.message(`@${cmd.keyword} berhasil ditambahkan menjadi moderator bot ini`); | |
} else { | |
req.room.message(`hanya owner bot yang bisa eueu`); | |
} | |
} else if (cmd.command == 'unmod') { | |
if(is_admin(username)) { | |
let admins = jsonfile.readFileSync(`./admins.json`); | |
let index = admins.moderator.indexOf(cmd.keyword); | |
if (index > -1) { | |
admins.moderator.splice(index, 1); | |
} | |
jsonfile.writeFileSync(`./admins.json`, admins); | |
req.room.message(`berhasil menghapus @${cmd.keyword} dari moderator bot ini`); | |
} else { | |
req.room.message(`hanya owner bot yang bisa eueu`); | |
} | |
} else { | |
req.room.message(`Command: ${cmd.command} not found!`); | |
} | |
} | |
} | |
}); | |
function parse_result(result) { | |
if(result.length == 0) return `Gak ada hasilnya kak ;(`; | |
let output = `Ini kak hasil pencariannya\n`; | |
result.forEach((item) => { | |
output += `${item.title}: \n${item.link}\n\n`; | |
}) | |
return output; | |
} | |
function simsimi(message) { | |
message = encodeURI(input_filter(message)); | |
let url = `https://secureapp.simsimi.com/v1/simsimi/talkset?uid=236406240&av=6.8.2.6&lc=id&cc=ID&tz=Asia%2FMakassar&os=a&ak=WUqJ4fqjokoyiMrcvc6SiBobe60%3D&message_sentence=${message}&normalProb=2&isFilter=1&talkCnt=1&talkCntTotal=1&session=BS79CMMMSr75g3Pri1N7sUithk54iztJoErrFZ2GRhQSYyR91jfk2jSS1oWwZnX7JJnzCCFVYTWxg5vqbg3NDKc2&triggerKeywords=%5B%5D`; | |
return tool.curl(url) | |
.then((res) => { | |
let response = JSON.parse(res.body); | |
message = (response.simsimi_talk_set.answers[0].sentence || typeof response.simsimi_talk_set.answers[0].sentence !== 'undefined') ? response.simsimi_talk_set.answers[0].sentence : ''; | |
// if(typeof response.respSentence == 'undefined') response.respSentence = 'apa kakak ganteng?'; | |
return output_filter(message); | |
}) | |
} | |
function input_filter(message) { | |
if(typeof message == 'undefined' || !message) message = 'hai'; | |
message = message.replace(/\@shillabot/g, ''); | |
if(message.length == 1) message = 'hai'; | |
return message.replace(/silla|sila|shila|shilla/ig, 'simi'); | |
} | |
function output_filter(message) { | |
if(typeof message == 'undefined' || !message) message = `aku gak ngerti kaka ;('`; | |
return message.replace(/simi|simsimi|simisimi/ig, 'aku'); | |
} | |
function reply_if(user) { | |
let admins = jsonfile.readFileSync(`./admins.json`); | |
let result = false; | |
for (var key in admins) { | |
if (admins.hasOwnProperty(key)) { | |
admins[key].forEach((admin) => { | |
if(user == admin) result = true; | |
}) | |
} | |
} | |
return result; | |
} | |
function ignore(user) { | |
let ignore = jsonfile.readFileSync(`./ignore.json`); | |
let result = false; | |
ignore.forEach((ignore) => { | |
if(user == ignore) result = true; | |
}) | |
return result; | |
} | |
function is_admin(user) { | |
let admins = jsonfile.readFileSync(`./admins.json`); | |
let result = false; | |
admins.owner.forEach((admin) => { | |
if(user == admin) result = true; | |
}) | |
return result; | |
} | |
function get_admin(user) { | |
let admins = jsonfile.readFileSync(`./admins.json`); | |
let result = `RANK LIST\n\n`; | |
for (let key in admins) { | |
if (admins.hasOwnProperty(key)) { | |
result += `${key}: ${admins[key].join(', ')}\n`; | |
} | |
} | |
return result; | |
} | |
function filter_command(pesan) { | |
let filter = pesan.split(' '); | |
if(filter.length > 0) { | |
let command = filter[0]; | |
filter.shift(); | |
let keyword = filter.join(' '); | |
let choosen = keyword.split(':'); | |
let choose = choosen[choosen.length-1].trim(); | |
choose = parseInt(choose) ? parseInt(choose) : false; | |
if(choosen.length > 1) { | |
choosen.splice(-1,1); | |
keyword = choosen.join(' ').trim(); | |
} | |
if(/\;/.test(command.charAt(0))) return {command: command.replace(';', ''), keyword, choose}; | |
return false; | |
} | |
return false; | |
} | |
function urlEncode(str){ | |
str=escape(str); | |
str=str.replace(new RegExp('\\+','g'),'%2B'); | |
return str.replace(new RegExp('%20','g'),'+'); | |
} | |
function parseMAL(done) { | |
let out = `${done.poster}\n`; | |
out += `Title: ${done.title}\n`; | |
out += `Alternative Title: ${done.alternativeTitle}\n`; | |
out += `Total Episode: ${done.episodes}\n`; | |
out += `Genre: ${done.genre.join(', ')}\n ` | |
out += `Rating: ${done.rating}from ${done.votes}\n`; | |
out += `Release Date: ${done.releaseDate}\n`; | |
out += `Air Status: ${done.airStatus}\n`; | |
out += `Plot: ${done.plot}\n`; | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment