Class: Cinch::Plugins::AutoVOP

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/autovop.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AutoVOP

Format for :enabled_channels: => :voice, “#channel2” => :op


17
18
19
20
# File 'lib/cinch/plugins/autovop.rb', line 17

def initialize(*args)
  super
  config[:enabled_channels] = {} if !config.has_key?(:enabled_channels) # Create hash for enabled_channels if key doesn't exist in config.
end

Instance Method Details

#execute(m, type, option) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cinch/plugins/autovop.rb', line 42

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

#on_connect(m) ⇒ Object


23
24
25
26
# File 'lib/cinch/plugins/autovop.rb', line 23

def on_connect(m)
  # Convert all string channels to Channel objects.
  config[:enabled_channels].each_with_object({}) {|(k,v), memo| memo[Channel(k)] = v }
end

#on_join(m) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cinch/plugins/autovop.rb', line 29

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