Bots Home
|
Create an App
Hodor!
Author:
glenn2507
Description
Source Code
Launch Bot
Current Users
Created by:
Glenn2507
/* * ------ HODOR by Glenn205 ------ * * (Based on Blapp by Prnsvh) * */ // hodor var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; var hodor_command = 'hodor'; var unhodor_command = 'unhodor'; var hodor_detail_command = 'detail'; var change_refresh_time_command = 'refresh'; var hodored = []; function log(msg) { cb.log(msg); } function hodor(username, time, originator) { if(username == originator) { cb.chatNotice('You cannot hodor yourself ' + originator + "!", originator); } else { log(username + ' is being hodored by ' + originator); if(username in hodored) { cb.chatNotice(username + ' already hodored!', originator); } else { if(username == cb.room_slug) { cb.chatNotice(originator + ' tried to hodor you!', cb.room_slug); cb.chatNotice('You cannot hodor the broadcaster!', originator); } else { var hodortime = new Date(); var timeint = parseInt(time, 10); hodored[username] = {'time': hodortime, 'duration': timeint}; cb.chatNotice(username + ' has been hodored by ' + originator + (timeint === 0 ? '' : ' for ' + timeint + ' seconds') + '!'); log(username + ' is now hodored ' + (timeint === 0 ? 'indefinitely' : 'for ' + timeint + ' seconds')); } } } updateHodorerPanel(); } function unhodor(username, originator) { if(username == originator) { cb.chatNotice('You cannot unhodor yourself ' + originator + "!", originator); } else { log(username + ' is being unhodored by ' + originator); if(username in hodored) { delete hodored[username]; cb.chatNotice(username + ' has been forgiven by ' + originator + ' and is no longer hodored...'); log(username + ' is now unhodored'); } else { cb.chatNotice(username + ' was not hodored!', originator); } } updateHodorerPanel(); } function is_hodored(username) { if(username in hodored) { var hodordata = hodored[username]; if(hodordata.duration === 0) { log('(info) ' + username + ' hodored indefinitely'); return true; } var remaining = hodorifiedfor(username); if(remaining == 0) { log('(info) ' + username + ' released'); unhodor(username, 'the powers of justice; a.k.a. "he served his time"'); return false; } log('(info) ' + username + ' hodored for another ' + remaining + ' seconds'); return true; } else { log('(info) ' + username + ' is not hodored'); return false; } } function hodorifiedfor(username) { if(username in hodored) { var hodordata = hodored[username]; if(hodordata.duration === 0) { return -1; } var now = new Date(); var released = new Date(hodordata.time.getTime()); released.setSeconds(released.getSeconds() + hodordata.duration); return Math.max(0, Math.ceil((released.getTime() - now.getTime()) / 1000)); } return 0; } function hodorify(msg) { log('hodorify: ' + msg); var replacement = 'hodor'; if(cb.settings.char_seq == 'random letters') { replacement = ''; for(var i = 0; i < 20; i++) { replacement += alphabet.charAt(Math.floor(Math.random() * alphabet.length)); } } var replacementl = replacement.length; var retv = ''; var modindex = 0; for(var j = 0, len = msg.length; j < len; j++) { if (msg[j] == ' ') { retv += ' '; modindex = 0; } else { if(/[.,?!;:]/.test(msg[j])) { retv += msg[j]; } else { retv += replacement[modindex%replacementl]; } modindex++; } } return retv; } function countHodored() { var cnt = 0; for(var prop in hodored) { if(is_hodored(prop)) { cnt++; } } return cnt; } function hodorDetails(user) { log('sending details to ' + user); cb.chatNotice('== Hodor! ' + countHodored() + ' users hodored ==', user); for(var prop in hodored) { if (hodored.hasOwnProperty(prop)) { var remaining = hodorifiedfor(prop); cb.chatNotice(prop + ' is hodored ' + (remaining > 0 ? 'for another ' + remaining + ' seconds' : 'indefinatily'), user) } } } function updateHodorerPanel() { cb.drawPanel(); } // hooks cb.settings_choices = [ {name:'allow_hodor', label:'Allowed to hodor', type:'choice', choice1:'allow broadcaster to hodor', choice2:'allow broadcaster and mods to hodor'}, {name:'char_seq', label:'hodor-type', type:'choice', choice1:'hodor', choice2:'random letters'}, //{name:'allow_tip_for_freedom', label:'Tip for freedom', type:'choice', choice1:'yes', choice2:'no'}, {name:'refresh_time', label:'Refresh', type:'choice', choice1:'very fast (every second - might cause lagging in busy rooms)', choice2:'fast (every 5 seconds)', choice3:'medium (every 10 seconds)', choice4:'slow (every 30 seconds)', choice5:'very slow (every 60 seconds - almost no overhead)', choice6:'off'} ]; cb.onDrawPanel(function (user) { if(user == cb.room_slug) // broadcaster panel --> TODO: modcheck (currently not supported) { return { 'template':'3_rows_of_labels', 'row1_label':'Users hodored:', 'row1_value':countHodored(), 'row2_label':'To hodor:', 'row2_value':'/hodor username [time]', 'row3_label':'To unhodor:', 'row3_value':'/unhodor username' }; } else if(is_hodored(user)) // hodored panel { var remaining = hodorifiedfor(user); return { 'template':'3_rows_11_21_31', 'row1_value':'', 'row2_value':'You are hodored' + (remaining > 0 ? ' for another ' + remaining + ' seconds!' : '!'), 'row3_value':'' }; } else // regular panel { return { 'template':'3_rows_11_21_31', 'row1_value':'Hodor mode:', 'row2_value':(cb.settings.allow_hodor == 'allow broadcaster and mods to hodor') ? 'Broadcaster and mods can hodor.' : 'Only broadcaster can hodor.', 'row3_value':'' }; } }); cb.onMessage(function (msg) { // vars for ease of use var m = msg['m']; var u = msg['user']; // check for action if(m[0] == '/') { // don't print commands msg['X-Spam'] = true; // check if user can perform actions var broadcasteronly = (cb.settings.allow_hodor == 'allow broadcaster to hodor'); if(broadcasteronly && u != cb.room_slug) { cb.chatNotice('Only the broadcaster can hodor!', u); } else if(!broadcasteronly && !msg['is_mod'] && u != cb.room_slug) { cb.chatNotice('Only the broadcaster and moderators can hodor!', u); } else { var command = m.substr(1); var commandparts = command.split(' '); if(commandparts[0] == hodor_command && commandparts.length > 1) // HODOR { var timeout = 0; if(commandparts.length > 2 && !isNaN(commandparts[2])) { timeout = commandparts[2]; } hodor(commandparts[1], timeout, u); } else if(commandparts[0] == unhodor_command && commandparts.length > 1) // UNHODOR { unhodor(commandparts[1], u); } else if(commandparts[0] == hodor_detail_command) // DETAIL { hodorDetails(u); } else if(commandparts[0] == change_refresh_time_command && commandparts.length > 1 && !isNaN(commandparts[1])) // REFRESH { updateRefreshTime(commandparts[1]); } } } else if(is_hodored(u)) { m = hodorify(m); var remaining = hodorifiedfor(u); if(remaining > 0) { cb.chatNotice('You are hodored for another ' + remaining + ' seconds!', u); } } msg['m'] = m; return msg; }); // auto update panel every X seconds var updatetime = 0; function initAutoUpdate() { if(cb.settings.refresh_time == 'very fast (every second - might cause lagging in busy rooms)') { updatetime = 1000; } else if(cb.settings.refresh_time == 'fast (every 5 seconds)') { updatetime = 5000; } else if(cb.settings.refresh_time == 'medium (every 10 seconds)') { updatetime = 10000; } else if(cb.settings.refresh_time == 'slow (every 30 seconds)') { updatetime = 30000; } else if(cb.settings.refresh_time == 'very slow (every 60 seconds - almost no overhead)') { updatetime = 60000; } if(updatetime > 0) { setTimeout(autoUpdateHodorerPanel, updatetime); } } function updateRefreshTime(seconds) { var restart = (updatetime == 0); seconds = Math.max(0, parseInt(seconds)); updatetime = seconds * 1000; if(updatetime > 0) { cb.chatNotice('Hodorscreen will update every ' + seconds + ' seconds.'); if(restart) { autoUpdateHodorerPanel(); } } else { cb.chatNotice('Hodorscreen will not update automatically, updates will happen if actions are performed.'); } } function autoUpdateHodorerPanel() { updateHodorerPanel(); if(updatetime > 0) { setTimeout(autoUpdateHodorerPanel, updatetime); } } initAutoUpdate();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.