Created
September 26, 2011 19:15
-
-
Save jhsu/1243091 to your computer and use it in GitHub Desktop.
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
# mkick.rb | |
# | |
# Mass-kicks users in a channel | |
# | |
# http://scripts.irssi.org/html/mkick.pl.html | |
# | |
# Possible inspiration: http://weechat.org/files/scripts/unofficial/chanlist.rb | |
# | |
# Usage: /mkick <channel> <kick message> | |
SCRIPT_NAME = "mkick" | |
SCRIPT_AUTHOR = "Troubleman <[email protected]>, Joseph Hsu <[email protected]>" | |
SCRIPT_DESC = "Mass-kicks users in a channel" | |
SCRIPT_VERSION = "0.1" | |
SCRIPT_LICENSE = "GPL3" | |
# TODO: implement similar to irssi mkick | |
# Usage: /MKICK [options] [mode] [mask] [reason] | |
# Options: | |
# -n normal kick | |
# -6 '2+4' kickmethod | |
# Mode: | |
# -a all on channel | |
# -o chops | |
# -v chvoices | |
# -d users without op | |
# -l users without op and voice | |
# Settings. | |
# /SET masskick_default_reason [reason] | |
# /SET masskick_default_use_6method [On/Off] | |
# | |
# settings = { | |
# "seconds_between_kicks": "5", | |
# "ignore_nicknames": "nick1, nick2, nick3", | |
# "ignore_strings_in_hostnames": "staff, admin, ntnu" | |
# } | |
def weechat_init | |
Weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_DESC, SCRIPT_VERSION, SCRIPT_LICENSE, "", "") | |
Weechat.config_set_plugin('default_kick_reason', 'Mass Kicked') unless Weechat.config_is_set_plugin('default_kick_reason') == 1 | |
Weechat.config_set_plugin('user_global_whitelist', '') unless Weechat.config_is_set_plugin('user_global_whitelist') == 1 | |
Weechat.config_set_plugin('host_global_whitelist', '') unless Weechat.config_is_set_plugin('host_global_whitelist') == 1 | |
Weechat.config_set_plugin('kick_interval', '5') unless Weechat.config_is_set_plugin('kick_interval') == 1 | |
# weechat.hook_command(command, description, args, args_description, completion, callback, callback_data) | |
Weechat.hook_command("mkick", "mass kick users from current channel that are not on the whitelist", | |
"[reason]", "[resason] reason for kicking", | |
"", | |
"mass_kick", "") | |
return Weechat::WEECHAT_RC_OK | |
end | |
# kick all users of the current channel | |
def mass_kick(data, buffer, args) | |
reason = (args && !args.empty?) ? args : Weechat.config_get_plugin('default_kick_reason') | |
server = Weechat.buffer_get_string(buffer, 'localvar_server') | |
channel = Weechat.buffer_get_string(buffer, 'localvar_channel') | |
infolist = Weechat.infolist_get("irc_nick", '', "#{server},#{channel}") | |
users = [] | |
safelist = whitelist(server, channel, 'user') | |
# host_safelist = whitelist(server, channel, 'host') | |
current_nick = Weechat.info_get('irc_nick', "#{server}") | |
while Weechat.infolist_next(infolist) == 1 | |
nick = Weechat.infolist_string(infolist, 'name') | |
host = Weechat.infolist_string(infolist, 'host').scan(/@(\S+)/).flatten.first.to_s.downcase | |
full_info = "#{nick}!#{host}" | |
unless nick == current_nick || safelist.include?(nick.downcase) # || host_safelist.include?(host) # TODO: hostname matching | |
users << full_info | |
end | |
end | |
# kick_interval = Weechat.config_is_set_plugin('host_global_whitelist') == 1 ? Weechat.config_get_plugin('kick_interval').to_i : 5 | |
# users.each do |nick| | |
# Weechat.command(buffer, "/kick #{nick} #{reason}") | |
# sleep(kick_interval) | |
# end | |
Weechat.print(buffer, reason) | |
Weechat.print(buffer, users.join(",")) | |
end | |
# Get nick/hostname whitelist for channel | |
def whitelist(server, channel, scope="user") | |
config_name = "#{scope}_whitelist.#{server}#{channel}" | |
if Weechat.config_is_set_plugin(config_name) == 0 | |
whitelist = Weechat.config_get_plugin(config_name) | |
else | |
whitelist = "" | |
Weechat.config_set_plugin(config_name, whitelist) | |
end | |
# user_global_whitelist or host_global_whitelist | |
( whitelist.split(/\s*,\s*/).map(&:downcase) + | |
Weechat.config_get_plugin("#{scope}_global_whitelist").split(/\s*,\s*/) ).select {|nick| | |
!nick.empty? } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment