Created
June 29, 2012 19:21
-
-
Save mseymour/3020081 to your computer and use it in GitHub Desktop.
AutoVOP plugin v 1.0
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
module Cinch | |
module Helpers | |
def check_user(channel, user, ignored_members=["v"]) | |
ignored_members ||= [] # If nil, assign an empty array. | |
users = Channel(channel).users # All users from supplied channel | |
modes = @bot.irc.isupport["PREFIX"].keys - ignored_members # | |
modes.any? {|mode| users[user].include?(mode)} | |
end | |
end | |
end |
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_relative "../helpers/check_user" | |
module Cinch | |
module Plugins | |
class AutoVOP | |
include Cinch::Plugin | |
set plugin_name: "AutoVOP", | |
help: "Automatically voices/ops nicks upon join.\nUsage: `!auto(op|voice) [on|off]` -- turns autoop/voice on or off. (Chanops only)", | |
react_on: :channel, | |
required_options: [:enabled_channels] | |
# Format for :enabled_channels: | |
# {"#channel1" => :voice, "#channel2" => :op} | |
listen_to :connect, method: :on_connect | |
def on_connect(m) | |
# Convert all string channels to Channel objects. | |
config[:enabled_channels].inject({}) {|memo, (k,v)| memo[Channel(k)] = v; memo; } | |
end | |
listen_to :join, method: :on_join | |
def on_join(m) | |
return if m.user == bot || !config[:enabled_channels].has_key?(m.channel) | |
sleep 0.5 # In case Chanserv/etc. has already given the user a mode. | |
return if check_user(m.channel, m.user, nil) # Return if user was already given a mode via chanserv, etc. | |
cmode = config[:enabled_channels][m.channel] | |
if cmode == :op | |
m.channel.op(m.user) | |
elsif cmode == :voice | |
m.channel.voice(m.user) | |
end | |
end | |
match /auto(op|voice) (on|off)$/ | |
def execute(m, type, option) | |
return unless check_user(m.channel, m.user, %w{h v}) | |
state = option == 'on' | |
if state | |
config[:enabled_channels][m.channel] = type.to_sym | |
else | |
config[:enabled_channels].delete(m.channel) | |
end | |
m.reply "Auto#{type} is now #{Format((state ? :green : :red), :bold, option)} for #{Format(:bold,m.channel.name)}." | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment