Created
September 12, 2017 15:35
-
-
Save BtbN/819430bfbcc9c1e72a1605b3a826a1d0 to your computer and use it in GitHub Desktop.
nameCommand.js
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
| /* | |
| * nameCommand.js | |
| * | |
| * This module returns a random name that was active in the last 10 minutes | |
| */ | |
| (function() { | |
| var ACTIVITY_DELAY_TIME_MS = 10 * 60 * 1000; | |
| $.bind('ircChannelMessage', function(event) { | |
| var sender = event.getSender().toLowerCase(); | |
| var time_ms = $.systemTime(); | |
| $.inidb.set('name_lastmsg', sender, time_ms); | |
| }); | |
| $.bind('command', function(event) { | |
| var i, command = event.getCommand(); | |
| if (command.equalsIgnoreCase('name')) { | |
| var min_time = $.systemTime() - ACTIVITY_DELAY_TIME_MS; | |
| var ulist = $.inidb.GetKeyList('name_lastmsg', ''); | |
| var flist = []; | |
| for(i in ulist) { | |
| var utime = parseInt($.inidb.get('name_lastmsg', ulist[i])); | |
| if(utime >= min_time) { | |
| flist.push(ulist[i]); | |
| } else { | |
| $.inidb.del('name_lastmsg', ulist[i]); | |
| } | |
| } | |
| $.say('Random Name: ' + $.username.resolve($.randElement(flist))); | |
| } | |
| }); | |
| $.bind('initReady', function() { | |
| $.registerChatCommand('./commands/nameCommand.js', 'name', 2); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment