Created
September 25, 2011 18:47
-
-
Save mseymour/1240956 to your computer and use it in GitHub Desktop.
RemoteAdmin - message relayer
This file contains 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
require 'obj_ext/string' | |
module Plugins | |
class RemoteAdmin | |
include Cinch::Plugin | |
set help: "Relays certain messages to logged-in admins.", required_options: [:admins] | |
listen_to :notice | |
listen_to :private | |
listen_to :ctcp | |
def listen m, message = nil, target = nil | |
config[:admins].each_admin {|nick| | |
admin = User(nick) | |
string = if m.ctcp? | |
m.ctcp_message | |
elsif !message.nil? | |
message | |
else | |
m.message | |
end | |
admin.msg fmt_message(nick: m.user.nick, type: (m.ctcp? ? "CTCP" : m.command), string: string) | |
} | |
end | |
listen_to :admin, method: :listen_hook | |
listen_to :private_admin, method: :listen_hook | |
def listen_hook m, message, target | |
config[:admins].each_admin {|nick| | |
admin = User(nick) | |
#admin.msg m.events.inspect | |
admin.msg fmt_message(nick: target.name, type: (!target.nil? ? target.name : m.command), string: (!message.nil? ? message : m.message)) | |
} | |
end | |
listen_to :antispam, method: :listen_hook_antispam | |
def listen_hook_antispam m, message, target | |
config[:admins].each_admin {|nick| | |
admin = User(nick) | |
admin.msg fmt_message(nick: m.user.nick, type: (!target.nil? ? target.name : m.command), string: (!message.nil? ? message : m.message)) | |
} | |
end | |
def fmt_message params={} | |
params = { | |
nick: "?", | |
type: "---", | |
string: "" | |
}.merge params | |
"![b]%<type>s![b] [%<nick>s] %<string>s".irc_colorize % params | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment