include XChatRuby #====================================================================== # ** Minkoff's Plugin #====================================================================== class Plugin < XChatRubyPlugin #------------------------------------------------------------------ # * Initialize #------------------------------------------------------------------ def initialize # User access list @authed_users = ['Minkoff_', 'Teloch', 'Claw', 'Wulf', 'ElFuzzo', 'Tylerofl'] # Create command arrays @comm_queue = [] @ext_comm_queue = [] @msg_queue = [] # Hook parser, timer, and auth hook_server('PRIVMSG', XCHAT_PRI_NORM, method(:server_privmsg), nil) hook_server('NOTICE', XCHAT_PRI_NORM, method(:server_notice), nil) hook_timer(500, method(:timer_message), nil) # Automatically hook all commands @commands = [] for method in Plugin.instance_methods command = method.scan(/^command_(.*)$/)[0] if command hook_command(command[0], XCHAT_PRI_NORM, method(('command_' + command[0]).intern), '') @commands.push(command[0]) end end # Print load confirmation puts 'Loaded Admin Command Plugin' end #------------------------------------------------------------------ # * PRIVMSG Server Hook #------------------------------------------------------------------ def server_privmsg(words, words_eol, data) # Define some variables for easy handling usr, chan, msg = words[0].scan(/:([^!]+)/)[0][0], words[2], words_eol[3][1,words_eol[3].length - 1] # Queue command if valid if command = msg.scan(/^!(([a-z1-9]+)( .*)?)/)[0] if @authed_users.include?(usr) and @commands.include?(command[1]) @ext_comm_queue.push([command[0], usr]) command('ns status ' + usr) end end # Parse for smilies in #slackdev if (chan == "#slackdev" and get_info('channel') == "#slackdev") or (chan == "#lol" and get_info('channel') == "#lol") if smile = msg.scan(/(<\^>|\\m\/|(LOL|LMF?AO)(:\|)?[1!]*|<3|[cC]+[lL]+[aA][aA]+[wW]+|d\(\^_\^\)b|\S?[=:;8B]([{[oS<]\S?|[-~^']*\S)(GC)?|OGC|([^-_. ])(\.|[_-]+)\6|([;<>@^])\8|o_\S*)/)[0] rand(15) == 0 ? command('fig ' + smile[0]) : @msg_queue.push([chan, smile[0]]) end end end #------------------------------------------------------------------ # * NOTICE Server Hook #------------------------------------------------------------------ def server_notice(words, words_eol, data) # Define some variables for easy handling usr, msg = words[0].scan(/:([^!]+)/)[0][0], words_eol[3][1,words_eol[3].length - 1] # Execute command if user is logged in if usr == 'NickServ' and info = msg.scan(/^STATUS (\S+) ([0-9])/)[0] if @ext_comm_queue.size > 0 and @ext_comm_queue[0][1] == info[0] command(@ext_comm_queue[0][0]) if info[1] == '3' @ext_comm_queue.shift return XCHAT_EAT_ALL end end end #------------------------------------------------------------------ # * Message Timer #------------------------------------------------------------------ def timer_message(data) if !@msg_queue.empty? chan, msg = @msg_queue.shift command('msg ' + chan + ' ' + msg) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Say Command #------------------------------------------------------------------ def command_say(words, words_eol, data) words_eol[1] = ' ' if !words_eol[1] @msg_queue.push([get_info('channel'), words_eol[1]]) return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Clear Command #------------------------------------------------------------------ def command_clear(words, words_eol, data) @msg_queue.clear return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * List Command #------------------------------------------------------------------ def command_list(words, words_eol, data) command('say Commands: !' + @commands.join(', !')) return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Flood Command #------------------------------------------------------------------ def command_flood(words, words_eol, data) for i in 1..words_eol[1].length command('say ' + words_eol[1][0,i]) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Pyramid Command #------------------------------------------------------------------ def command_pyramid(words, words_eol, data) for i in 1..words_eol[1].length next if i % 2 != words_eol[1].length % 2 command('say ' + " " * ((words_eol[1].length - i) / 2) + words_eol[1][0,i]) # / end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * MD5 Command #------------------------------------------------------------------ def command_md5(words, words_eol, data) command('say ' + md5(words_eol[1])) return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * MD5F Command #------------------------------------------------------------------ def command_md5f(words, words_eol, data) for i in 1..words_eol[1].length command('say ' + words_eol[1][0,i] + ' ' + md5(words_eol[1][0,i])) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Fig Command #------------------------------------------------------------------ def command_fig(words, words_eol, data) command('figx 1 ' + words_eol[1]) return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * FigF Command #------------------------------------------------------------------ def command_figf(words, words_eol, data) for i in 1..words_eol[1].length command('fig ' + words_eol[1][0,i]) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * FigX Command #------------------------------------------------------------------ def command_figx(words, words_eol, data) if words[2] message = words_eol[2] for i in 0...words[1].to_i message = `figlet "#{message}"` end for line in message.split("\n") command('say ' + line) end end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Vert Command #------------------------------------------------------------------ def command_vert(words, words_eol, data) words = words_eol[1].scan(/\S+/) lines, max = [], 0 for word in words max = [word.length, max].max end for i in 0..words.size - 1 chars = words[i].scan(/./) for j in 0..max - 1 lines[j] = '' if !lines[j] chars[j] = ' ' if !chars[j] lines[j] += chars[j] + ' ' end end for line in lines command('say ' + line) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * Rhythmbox Command #------------------------------------------------------------------ def command_rhythmbox(words, words_eol, data) fd = `ls -al /proc/\`pidof rhythmbox\`/fd` # / if file = fd.scan(/\/.+\/(.+)\.(mp3|ogg)$/)[0] command('me >> ' + file[0]) end return XCHAT_EAT_ALL end #------------------------------------------------------------------ # * MD5 #------------------------------------------------------------------ def md5(string) string = '"' + string + '"' if string.include?(' ') return `md5sum --string=#{string};`[0,32] end end