Skip to content

Instantly share code, notes, and snippets.

@mseymour
Created November 6, 2011 06:04
Show Gist options
  • Save mseymour/1342541 to your computer and use it in GitHub Desktop.
Save mseymour/1342541 to your computer and use it in GitHub Desktop.
Admin handler + automatic +vhoa of bot admins
# -*- coding: utf-8 -*-
require 'modules/helpers/table_format'
module Plugins
module Admin
class Handler
include Cinch::Plugin
set(
plugin_name: "admin",
help: "Admin handler -- handles admins, of course.",
required_options: [:admins],
react_on: :private)
def login m, user, password
return "You are already here, #{user.nick}." unless !config[:admins].logged_in? user.mask
result = config[:admins].login! user.mask, password
if result
@bot.handlers.dispatch :admin, m, "#{user.nick} has been successfully logged in.", user
"Welcome back, #{user.nick}."
else
@bot.handlers.dispatch :admin, m, "#{user.nick} tried to login with the password `#{password}` but failed.", user
"#{user.nick}, your password is incorrect."
end
end
match /^login (.+)/, method: :execute_login, use_prefix: false
def execute_login m, password
m.user.msg login(m, m.user, password), true
end
match /^logout/, method: :execute_logout, use_prefix: false
def execute_logout m
return unless config[:admins].logged_in? m.user.mask
config[:admins].logout! m.user.mask
m.user.msg "Sayonara, #{m.user.nick}.", true
@bot.handlers.dispatch :admin, m, "#{user.nick} has successfully logged out.", m.target
end
match /^flogout/, method: :execute_flogout, use_prefix: false
def execute_flogout m
return unless config[:admins].logged_in? m.user.mask
hosts = []
config[:admins].each_admin {|host|
config[:admins].logout! host
#m.user.msg "Sayonara, #{m.user.nick}.", true
@bot.handlers.dispatch :admin, m, "#{host.match(/(.+)!(.+)@(.+)/)[1]} has successfully logged out by #{m.user.nick}.", m.target
}
end
match /^list admins/, method: :execute_admins, use_prefix: false
def execute_admins m
return unless config[:admins].logged_in? m.user.mask
m.user.msg Helpers::table_format(config[:admins].masks, regexp: /(?:(.+)!)?(.+)/, gutter: 1, justify: [:right,:left], headers: ["nick","username+host"]), true
end
listen_to :nick, method: :listen_nick
def listen_nick m
return unless config[:admins].logged_in?(m.user.mask("#{m.user.last_nick}!%u@%h"))
config[:admins].update m.user.mask("#{m.user.last_nick}!%u@%h"), m.user.mask
@bot.debug "Updated hostmask. (`#{m.user.mask("#{m.user.last_nick}!%u@%h")}` -> `#{m.user.mask}`)"
@bot.handlers.dispatch :admin, m, "`#{m.user.last_nick}` changed their nick to `#{m.user.nick}`.", m.target
end
listen_to :quit, method: :listen_quit
def listen_quit m
#outgoing_mask = "#{m.user.nick}!#{m.user.data[:user]}@#{m.user.data[:host]}"
return unless config[:admins].logged_in?(m.prefix)
config[:admins].logout! m.prefix #change back to m.user.mask once fixed in cinch
@bot.debug "#{m.prefix} has been automagically logged out."
@bot.handlers.dispatch :admin, m, "`#{m.prefix}` has been logged out because they quit the server.", m.target
end
end
class LevelUpper
include Cinch::Plugin
set(
plugin_name: "level upper",
help: "Level upper -- .",
required_options: [:admins])
listen_to :join, method: :listen_join
def listen_join m
return unless config[:admins].logged_in?(m.prefix)
botu = User(@bot.nick)
# if halfop, voice. if op, halfop or voice. if admin, op.
# qaohv
# aohv-
# (shift?)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment