# Author: # Copyright: All Content Unless Otherwise Stated Copyright © 2008 Foxonastick.com # License: BSD license require 'rbot/plugins' class BansV2Plugin < Plugin TimerRe = /^\d+[smhd]$/ ChannelRe = /^#+[^\s]+$/ def help(plugin, topic="") case plugin when "mute" return "mute [Xs/m/h/d] [#channel]: silence a user on the given channel for the given time. default is forever, on the current channel. not all servers support silencing users" when "unmute" return "unmute [#channel]: allow the given user to talk on the given channel. defaults to the current channel" end return "bansv2 : My own hacked up version of bans to support servers which can't use silence. The command silence is replaced by mute. Other modes/commands will be added later, check out rbot.foxonastick.com for news on the plugin. Commands are: [un]mute" end def silence_user(m, params=nil) puts "in silence_user" nick = params[:nick] host = m.server.user(nick).host puts params.inspect channel = check_channel(m, params[:channel]) timer = parse_timer(params[:timer]) puts "nick: #{nick} channel: #{channel} timer: #{timer}" @bot.sendq "MODE #{channel} +b ~q:#{host}" @bot.timer.add_once(timer) { @bot.sendq "MODE #{channel} -b ~q:#{host}" } if timer > 0 puts "done silence_user" end def unsilence_user(m, params=nil) puts "in unsilence_user" nick = params[:nick] host = m.server.user(nick).host puts params.inspect channel = check_channel(m, params[:channel]) @bot.sendq "MODE #{channel} -b ~q:#{host}" puts "done unsilence_user" end def check_channel(m, strchannel) begin raise "must specify channel if using privmsg" if m.private? and not strchannel channel = m.server.channel(strchannel) || m.target raise "I am not in that channel" unless channel.has_user?(@bot.nick) return channel rescue error $! m.reply $! end end def parse_timer(timer_in=nil) case timer_in when nil timer = 0 when /^(\d+)s$/ timer = $1.to_i when /^(\d+)m$/ timer = $1.to_i * 60 when /^(\d+)h$/ timer = $1.to_i * 60 * 60 when /^(\d+)d$/ timer = $1.to_i * 60 * 60 * 24 else raise "Wrong time specifications" end timer end end plugin = BansV2Plugin.new plugin.default_auth( 'act', false ) plugin.map 'mute :nick :timer :channel', :action => 'silence_user', :requirements => {:timer => BansV2Plugin::TimerRe, :channel => BansV2Plugin::ChannelRe}, :defaults => {:timer => nil, :channel => nil}, :auth_path => 'act' plugin.map 'unmute :nick :channel', :action => 'unsilence_user', :requirements => {:channel => BansV2Plugin::ChannelRe}, :defaults => {:channel => nil}, :auth_path => 'act'