Last active
January 18, 2018 13:59
-
-
Save kyujin-cho/424e4395a428569407cc50fc15665996 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
const tmi = require('tmi.js') | |
const exec = require('child_process').exec | |
const options = require('./config') | |
const axios = require('axios') | |
const http = require('http') | |
var client = new tmi.client(options) | |
let cons = {} | |
let statistic = {} | |
let loaded = false | |
axios.get('http://funzinnu.cafe24.com/stream/dccon.php') | |
.then((json) => { | |
cons = json.data | |
for(var key in json.data) | |
statistic[key] = 0 | |
loaded = true | |
}) | |
// Connect the client to the server.. | |
client.connect() | |
client.on('connected', (address, port) => { | |
client.join('#' + process.argv[2]) | |
}) | |
let build = '' | |
function resetStat() { | |
for(var key in statistic) | |
statistic[key] = 0 | |
client.say('#' + process.argv[2], '톤계 초기화 완료') | |
} | |
function sayStat() { | |
var items = Object.keys(statistic).map(function(key) { | |
return [key, statistic[key]]; | |
}) | |
// Sort the array based on the second element | |
items.sort(function(first, second) { | |
return second[1] - first[1]; | |
}) | |
if(items.length > 5) { | |
items = items.slice(0, 5) | |
} | |
client.say('#' + process.argv[2], '톤계맨-> ' + items.filter(item => item[1] > 0).map((item, index) => (index+1) + '위: ' + item[0] + '(' + item[1] + '회)').join(', ')) | |
} | |
setInterval(() => { | |
sayStat() | |
}, 1000 * 60 * 10) | |
client.on("message", function (channel, userstate, message, self) { | |
// Don't listen to my own messages.. | |
if (self) return; | |
if(message.indexOf('~') != -1 && loaded) { | |
message.split(' ').forEach((item, index) => { | |
if(item.indexOf('~') == 0 && cons[item.substring(1)]) { | |
statistic[item.substring(1)] += 1 | |
} | |
}) | |
} | |
if(message.startsWith('!디씨콘톤계') || message.startsWith('!디시콘톤계')) { | |
console.log(userstate) | |
sayStat() | |
} | |
if(message.startsWith('!토미건')) { | |
const number = Math.floor(Math.random() * 1171000) | |
client.say('#' + process.argv[2], new String(number).toString()) | |
} | |
if(message.startsWith('!톤계초기화')) { | |
if(userstate.username !== 'thy2134') return | |
resetStat() | |
} | |
}) | |
http.createServer((req, res) => { | |
resetStat() | |
res.write('Done') | |
res.end() | |
}).listen(13947) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment