Advertisement
Namasteh

Untitled

Feb 13th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.59 KB | None | 0 0
  1. require 'cinch'
  2. require_relative "config/check_user"
  3.  
  4. module Cinch::Plugins
  5.   class PrivChanCP
  6.     include Cinch::Plugin
  7.     include Cinch::Helpers
  8.     set :react_on, :private
  9.    
  10.     set :prefix, /^~/
  11.     set :plugin_name, 'privchancp'
  12.     set :help, <<-USAGE.gsub(/^ {6}/, '')
  13.       Private commands to allow you to control the channel functions of the bot.
  14.       Usage:
  15.       - ~kick <channel> <nick> [<reason>]: This command must be used in a PM. Forces the bot to kick the specified user from the specified channel. Note: if you do not give a <reason> the bot will not give one either.
  16.       - ~ban <channel> <nick>: This command must be used in a PM. Forces the bot to ban the specified user from the specified channel.
  17.       - ~unban <channel> <mask>: This command must be used in a PM. Forces the bot to unban a specified mask in the specified channel. Note: you must specify the mask or the bot can not unban the user.
  18.       - ~kban <channel> <nick> <reason>: This command must be used in a PM. Forces the bot to kick and ban the specified user from the specified channel with the specified reason. Note: if you do not specify the reason, the bot won't either.
  19.      - ~op <channel> <nick>: This command must be used in a PM. Forces the bot to op the specified user in the specified channel.
  20.      - ~deop <channel> <nick>: This command must be used in a PM. Forces the bot to deop the specified user in the specified channel.
  21.      - ~voice <channel> <nick>: This command must be used in a PM. Forces the bot to give the specified user voice in the specified channel.
  22.      - ~devoice <channel> <nick>: This command must be used in a PM. Forces the bot to take voice from the specified user in the specified channel.
  23.      - ~topic <channel> <topic>: This command must be used in a PM. Forces the bot to change the topic in the specified channel to the topic you specify.
  24.      USAGE
  25.    
  26.    # This will kick the user. This is nice if you're a nice admin and
  27.     # don't want to be seen kicking your friends for being n00bs! :p
  28.    
  29.     match /kick (#\S+) (\S+)\s?(.+)?/, method: :execute_kick
  30.    
  31.     def execute_kick(m, channel, knick, reason)
  32.       unless check_user(m.user)
  33.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  34.         bot.info("Received invalid kick command from #{m.user.nick}")
  35.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kick' command for #{channel} but was not authorized.") }
  36.       return;
  37.     end
  38.       unless bot.channels.include? Channel(channel)
  39.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  40.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kick' command for #{channel} but I am not in #{channel}.") }
  41.       return;
  42.     end
  43.       unless Channel(channel).opped?(m.bot) == true
  44.         m.reply ("I can't make a kick because I am not op in #{channel}")
  45.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kick' command for #{channel} but I am not op in #{channel}.") }
  46.       return;
  47.     end
  48.       unless Channel(channel).users.keys.include?(knick)
  49.         m.reply ("I can not kick #{knick} because #{knick} is not in #{channel}")
  50.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kick' command to kick #{knick} from #{channel} but #{knick} is not in #{channel}.") }
  51.       return;
  52.     end
  53.         bot.info("Received valid kick command from #{m.user.nick}")
  54.         m.reply Format(:green, "Very well...")
  55.         Channel(channel).kick(knick, reason)
  56.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'kick' command to kick #{knick} from #{channel}. Reason: #{reason}") }
  57.       end
  58.    
  59.     # The nice thing about the following command is that it takes the nick
  60.     # that EVE is given and converts it into a ban-able mask. There is
  61.     # nothing I hate more as a chanop than having to copy paste the mask
  62.     # when a user is flooding or suffer the consequences of banning only
  63.     # the nick which can be easily evaded by a nick change.
  64.  
  65.     match /ban (#\S+) (\S+)/, method: :execute_ban
  66.  
  67.     def execute_ban(m, channel, user)
  68.       unless check_user(m.user)
  69.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  70.         bot.info("Received invalid ban command from #{m.user.nick}")
  71.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'ban' command for #{channel} on #{user} but was not authorized.") }
  72.       return;
  73.     end
  74.       unless bot.channels.include? Channel(channel)
  75.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  76.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'ban' command for #{channel} on #{user} but I am not in #{channel}.") }
  77.       return;
  78.     end
  79.       unless Channel(channel).opped?(m.bot) == true
  80.         m.reply ("I can't ban #{user} because I am not op in #{channel}")
  81.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'ban' command for #{channel} on #{user} but I am not op in #{channel}.") }
  82.       return;
  83.     end
  84.       unless Channel(channel).users.keys.include?(user)
  85.         m.reply ("I can not ban #{user} because #{user} is not in #{channel}")
  86.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'ban' command to ban #{user} from #{channel} but #{user} is not in #{channel}.") }
  87.       return;
  88.     end
  89.       bot.info("Received valid ban command from #{m.user.nick}")
  90.       user = User(user)
  91.       mask = user.mask("*!*@%h")
  92.       m.reply Format(:green, "Very well...")
  93.       Channel(channel).ban(mask)
  94.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'ban' command in #{channel} on #{user}. Banned mask: #{mask}") }
  95.     end
  96.    
  97.     # Sometimes you just have to unban a fella! Unfortunately now you have
  98.     # to do the work of defining the mask for the bot to unban. D:
  99.    
  100.     match /unban (#\S+) (\S+)/, method: :execute_unban
  101.  
  102.     def execute_unban(m, channel, mask)
  103.       unless check_user(m.user)
  104.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  105.         bot.info("Received invalid unban command from #{m.user.nick}")
  106.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'unban' command for #{channel} on #{mask} but was not authorized.") }
  107.       return;
  108.     end
  109.       unless bot.channels.include? Channel(channel)
  110.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  111.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'unban' command for #{channel} on #{mask} but I am not in #{channel}.") }
  112.       return;
  113.     end
  114.       unless Channel(channel).opped?(m.bot) == true
  115.         m.reply ("I can't unban #{mask} because I am not op in #{channel}")
  116.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'unban' command for #{channel} on #{mask} but I am not op in #{channel}.") }
  117.       return;
  118.     end
  119.       bot.info("Received valid unban command from #{m.user.nick}")
  120.       m.reply Format(:green, "Very well...")
  121.       Channel(channel).unban(mask)
  122.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'unban' command to unban #{mask} from #{channel}.") }
  123.     end
  124.    
  125.     # What better way to make your point but to kick and ban the annoying
  126.     # user at the same time! This instance just combines the ban and kick
  127.     # instances together to create one nice smooth package.
  128.    
  129.     match /kban (#\S+) (\S+)(?: (.+))?/, method: :execute_kban
  130.    
  131.     def execute_kban(m, channel, user, reason)
  132.       unless check_user(m.user)
  133.         sleep config[:delay] || 10
  134.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  135.         bot.info("Received invalid kban command from #{m.user.nick}")
  136.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kban' command for #{channel} on #{user} but was not authorized.") }
  137.       return;
  138.     end
  139.       unless Channel(channel).opped?(m.bot) == true
  140.         m.reply ("I can't kban #{user} because I am not op in #{channel}")
  141.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kban' command for #{channel} on #{user} but I am not op in #{channel}.") }
  142.       return;
  143.     end
  144.       unless Channel(channel).users.keys.include?(user)
  145.         m.reply ("I can not kick/ban #{user} because #{user} is not in #{channel}")
  146.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'kban' command to kick/ban #{user} from #{channel} but #{user} is not in #{channel}.") }
  147.       return;
  148.     end
  149.       bot.info("Received valid kban command from #{m.user.nick}")
  150.       user = User(user)
  151.       mask = user.mask("*!*@%h")
  152.       m.reply Format(:green, "Very well...")
  153.       Channel(channel).ban(mask)
  154.       Channel(channel).kick(user, reason)
  155.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'kban' command to kick and ban #{user} from #{channel}. Reason: #{reason} | Banned mask: #{mask}") }
  156.     end
  157.    
  158.     # Why not?
  159.    
  160.     match /op (#\S+) (\S+)(?: (.+))?/, method: :execute_rop
  161.    
  162.     def execute_rop(m, channel, user)
  163.       unless check_user(m.user)
  164.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  165.         bot.info("Received invalid op command from #{m.user.nick}")
  166.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'op' command for #{channel} on #{user} but was not authorized.") }
  167.       return;
  168.     end
  169.       unless bot.channels.include? Channel(channel)
  170.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  171.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'op' command for #{channel} on #{user} but I am not in #{channel}.") }
  172.       return;
  173.     end
  174.       unless Channel(channel).opped?(m.bot) == true
  175.         m.reply ("I can't op #{user} because I am not op in #{channel}")
  176.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'op' command for #{channel} on #{user} but I am not op in #{channel}.") }
  177.       return;
  178.     end
  179.       unless Channel(channel).opped?(user) == false
  180.         m.reply ("I can't op #{user} because they already have op in #{channel} Perhaps you meant to use the 'deop' command?")
  181.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'op' command for #{channel} on #{user} but #{user} already has op in #{channel}") }
  182.       return;
  183.     end
  184.       unless Channel(channel).users.keys.include?(user)
  185.         m.reply ("I can not op #{user} because #{user} is not in #{channel}")
  186.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'op' command to op #{user} in #{channel} but #{user} is not in #{channel}.") }
  187.       return;
  188.     end
  189.       bot.info("Received valid op command from #{m.user.nick}")
  190.       m.reply Format(:green, "Very well...")
  191.       bot.irc.send ("MODE #{channel} +o #{user}")
  192.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'op' command to give +o to #{user} in #{channel}.") }
  193.     end
  194.    
  195.     # This is for when you need to deop, duh! :P
  196.    
  197.     match /deop (#\S+) (\S+)(?: (.+))?/, method: :execute_rdop
  198.    
  199.     def execute_rdop(m, channel, user)
  200.       unless check_user(m.user)
  201.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  202.         bot.info("Received invalid deop command from #{m.user.nick}. User attempted to op #{user} in #{channel}")
  203.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'deop' command for #{channel} on #{user} but was not authorized.") }
  204.       return;
  205.     end
  206.       unless bot.channels.include? Channel(channel)
  207.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  208.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'deop' command for #{channel} on #{user} but I am not in #{channel}.") }
  209.       return;
  210.     end
  211.       unless Channel(channel).opped?(m.bot) == true
  212.         m.reply ("I can't deop #{user} because I am not op in #{channel}")
  213.         bot.info("Valid deop command failed because I am not op in #{channel}")
  214.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'deop' command for #{channel} on #{user} but I am not op in #{channel}.") }
  215.       return;
  216.     end
  217.       unless Channel(channel).opped?(m.bot) == true
  218.         m.reply ("I can't deop #{user} because #{user} does not have op in #{channel}. Perhaps you meant to use the 'op' command?")
  219.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'deop' command for #{channel} on #{user} but #{user} does not have op in #{channel}.") }
  220.       return;
  221.     end
  222.       unless Channel(channel).users.keys.include?(user)
  223.         m.reply ("I can not deop #{user} because #{user} is not in #{channel}")
  224.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'deop' command to deop #{user} in #{channel} but #{user} is not in #{channel}.") }
  225.       return;
  226.     end
  227.       bot.info("Received valid deop command from #{m.user.nick} for #{channel}")
  228.       m.reply Format(:green, "Very well...")
  229.       bot.irc.send ("MODE #{channel} -o #{user}")
  230.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'op' command to take +o from #{user} in #{channel}.") }
  231.     end
  232.    
  233.     # This mode (voice) is becoming obsolete. But why not add it to the
  234.     # list anyway?
  235.    
  236.     match /voice (#\S+) (\S+)(?: (.+))?/, method: :execute_rv
  237.    
  238.     def execute_rv(m, channel, user)
  239.       unless check_user(m.user)
  240.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  241.         bot.info("Received invalid voice command from #{m.user.nick}")
  242.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'voice' command for #{channel} on #{user} but was not authorized.") }
  243.       return;
  244.     end
  245.       unless bot.channels.include? Channel(channel)
  246.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  247.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'voice' command for #{channel} on #{user} but I am not in #{channel}.") }
  248.       return;
  249.     end
  250.       unless Channel(channel).opped?(m.bot) == true
  251.         m.reply ("I can't give voice to #{user} because I am not op in #{channel}")
  252.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'voice' command for #{channel} on #{user} but I am not op in #{channel}.") }
  253.       return;
  254.     end
  255.       unless Channel(channel).users.keys.include?(user)
  256.         m.reply ("I can not voice #{user} because #{user} is not in #{channel}")
  257.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'voice' command to voice #{user} in #{channel} but #{user} is not in #{channel}.") }
  258.       return;
  259.     end
  260.       bot.info("Received valid voice command from #{m.user.nick}")
  261.       m.reply Format(:green, "Very well...")
  262.       bot.irc.send ("MODE #{channel} +v #{user}")
  263.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'voice' command to give +v to #{user} in #{channel}.") }
  264.     end
  265.    
  266.     # We can take it away just as easily!
  267.    
  268.     match /devoice (#\S+) (\S+)(?: (.+))?/, method: :execute_rdv
  269.    
  270.     def execute_rdv(m, channel, user)
  271.       unless check_user(m.user)
  272.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  273.         bot.info("Received invalid devoice command from #{m.user.nick}")
  274.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'devoice' command for #{channel} on #{user} but was not authorized.") }
  275.       return;
  276.     end
  277.       unless bot.channels.include? Channel(channel)
  278.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  279.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'devoice' command for #{channel} on #{user} but I am not in #{channel}.") }
  280.       return;
  281.     end
  282.       unless Channel(channel).opped?(m.bot) == true
  283.         m.reply ("I can't take voice from #{user} because I am not op in #{channel}")
  284.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'devoice' command for #{channel} on #{user} but I am not op in #{channel}.") }
  285.       return;
  286.     end
  287.       unless Channel(channel).users.keys.include?(user)
  288.         m.reply ("I can not devoice #{user} because #{user} is not in #{channel}")
  289.         Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'devoice' command to devoice #{user} in #{channel} but #{user} is not in #{channel}.") }
  290.       return;
  291.     end
  292.       bot.info("Received valid devoice command from #{m.user.nick}")
  293.       m.reply Format(:green, "Very well...")
  294.       bot.irc.send ("MODE #{channel} -v #{user}")
  295.       Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'devoice' command to take +v from #{user} in #{channel}.") }
  296.     end
  297.    
  298.     # This could be fun and particularly useful in your channel if you set
  299.     # funny (and embarrassing) quotes from users in your topic. They won't
  300.     # know it's you!
  301.    
  302.     match /t (#.+?) (.+)/, method: :execute_topic
  303.    
  304.     def execute_topic(m, channel, topic)
  305.       unless check_user(m.user)
  306.         m.reply Format(:red, "You are not authorized to use this command! This incident will be reported!")
  307.         bot.info("Received invalid topic command from #{m.user.nick}")
  308.       return;
  309.     end
  310.       unless bot.channels.include? Channel(channel)
  311.         m.reply ("I'm sorry. I am not in #{channel}, please have me join that channel and op me in order for me to complete this action!")
  312.       return
  313.     end
  314.       unless Channel(channel).opped?(m.bot) == true
  315.         m.reply ("I can't change the topic in #{channel} because I am not op.")
  316.       return;
  317.     end
  318.       bot.info("Received valid topic command from #{m.user.nick}")
  319.       m.reply Format(:green, "Very well...")
  320.       bot.irc.send ("TOPIC #{channel} #{topic}")
  321.     end
  322.   end
  323. end
  324.  
  325. # A FEW NOTES:
  326. # 1.) If you need further help with the commands and their syntax just type !help in a channel
  327. # that Eve is in and she will send you a vast array of commands at your disposal.
  328. #
  329. # 2.) Please remember that these commands can be easily abused and you don't want to give the wrong
  330. # impression to chanops or IRCops, so please use with caution and permission. Also, don't add anyone
  331. # who doesn't have the common sense to do the same.
  332. #
  333. # As a last note, always remember that EVE is a project for a Top-Tier IRC bot, and the project
  334. # could always use more help. Feel free to contribute at the github:  https://github.com/Namasteh/Eve-Bot
  335. # For help with the Cinch framework you can always visit #Cinch at irc.freenode.net
  336. # For help with EVE you can always visit #Eve at rawr.coreirc.org
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement