Skip to content

Instantly share code, notes, and snippets.

@mseymour
Created June 29, 2012 19:21
Show Gist options
  • Save mseymour/3020081 to your computer and use it in GitHub Desktop.
Save mseymour/3020081 to your computer and use it in GitHub Desktop.
AutoVOP plugin v 1.0
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
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