User:Holographic Pearl/Code


 * 1) encoding: UTF-8

require 'thread' require 'socket' require 'json' require 'yaml' require 'httparty' require 'media_wiki'
 * 1) These are packages that the bot requires in order to run.

require_relative './plugin' require_relative './util' require_relative './events'
 * 1) These are filepaths that the bot needs.

class HoloPearl include Chatbot::Plugin # Version constant. VERSION = "13.0.4.3784" # Timestamp constants. CATEGORY_TS = '%d %B %Y' NAMING_TS = '%d %m %y' MESSAGE_TS = '%H|%M|%S' # Kick rules. NO_KICK = 0 NO_KICK_WHEN_NO_MODS = 1 NO_KICK_WHEN_MODS_ON = 2 NO_KICK_NEVER = 3 # Message listeners. match /(.*)/i, :use_prefix => false, :method => :onmessage # Event listeners. listen_to :join, :onjoin listen_to :part, :onpart listen_to :kick, :onkick listen_to :ban, :onban # Command listeners. match /^(?:!|\/|\\)(.+?(?=\b))(?:\s|)(|\S*)(?:\s|)(|\S*)(?:\s|)(|\S*)$/is, :use_prefix => false, :method => :commands # Initialize the class. def initialize(bot) super(bot) # Start up the logging processes. if !@client.config.key? "logging" @log_interval = 600 @log_title = 'Project:Chat/Logs/' @log_category = 'Wikia Chat logs' @client.config['logging'] = { 'interval' => @log_interval, 'title' => @log_title, 'category' => @log_category }			@client.save_config else @log_interval = @client.config['logging']['interval'] @log_title = @client.config['logging']['title'] @log_category = @client.config['logging']['category'] end # Logging variables. @log_file = nil @last_log = nil @log_thread = log_thread @log_mutex = Mutex.new # Start up the command processes. if !@client.config.key? "variables" @silent = false @seen = true @webcheck = true @vidcheck = false @informban = false @swearcheck = true @spamcheck = true @kickrule = NO_KICK_NEVER @editlimit = 0 @client.config['variables'] = { 'silent' => @silent, 'seen' => @seen, 'webcheck' => @webcheck, 'vidcheck' => @vidcheck, 'informban' => @informban, 'swearcheck' => @swearcheck, 'spamcheck' => @spamcheck, 'kickrule' => @kickrule, 'editlimit' => @editlimit }			@client.save_config else @silent = @client.config['variables']['silent'] @seen = @client.config['variables']['seen'] @webcheck = @client.config['variables']['webcheck'] @vidcheck = @client.config['variables']['vidcheck'] @informban = @client.config['variables']['informban'] @swearcheck = @client.config['variables']['swearcheck'] @spamcheck = @client.config['variables']['spamcheck'] @kickrule = @client.config['variables']['kickrule'] @editlimit = @client.config['variables']['editlimit'] end # Statistic variables. @stat_time = Time.now.to_i @stat_lines = 0 @stat_kicks = 0 @stat_bans = 0 @stat_joins = 0 @stat_leaves = 0 # Set up the swear list. if File.exists? 'swears.yml' @swearlist = YAML::load_file('swears.yml') else @swearlist = {'swears' => []} File.open('swears.yml', 'w+') do |f| f.write(@swearlist.to_yaml) end end @swearregex = "" first = true @swearlist['swears'].each do |swear| if first == true first = false else @swearregex = @swearregex + "|" end @swearregex = @swearregex + swear.gsub("\\", "\\b") end @swearregex = "(" + @swearregex + ")" @swearregex = %r[#{@swearregex}]ism # Set up the website whitelist. if File.exists? 'sites.yml' @sitelist = YAML::load_file('sites.yml') else @sitelist = {'sites' => []} File.open('sites.yml', 'w+') do |f| f.write(@sitelist.to_yaml) end end @siteregex = "" first = true @sitelist['sites'].each do |site| if first == true first = false else @siteregex = @siteregex + "|" end @siteregex = @siteregex + site end @siteregex = "(" + @siteregex + ")" @siteregex = %r[#{@siteregex}]ism # Set up the spam list. if File.exists? 'spam.yml' @spamlist = YAML::load_file('spam.yml') else @spamlist = {} File.open('spam.yml', 'w+') do |f| f.write(@spamlist.to_yaml) end end # Set up the seen list. if File.exists? 'seen.yml' @seenlist = YAML::load_file('seen.yml') else @seenlist = {} File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Tell us we're ready. puts "Bot is loaded and ready!" end # Check if string stuff matches. def matches?(text, regex) return !!(text =~ regex) end # Utility only, used to get a detailed timestamp. def get_hms(ts) years = ts / 31556926 ts %= 31556926 weeks = ts / 604800 ts %= 604800 days = ts / 86400 ts %= 86400 hours = ts / 3600 ts %= 3600 minutes = ts / 60 ts %= 60 ret = '' ret += "#{years} year#{years > 1 ? 's' & lengthy = true : ''}, " if years > 0 ret += "#{weeks} week#{weeks > 1 ? 's' & lengthy = true : ''}, " if weeks > 0 ret += "#{days} day#{days > 1 ? 's' & lengthy = true : ''}, " if days > 0 ret += "#{hours} hour#{hours > 1 ? 's' & lengthy = true : ''}, " if hours > 0 ret += "#{minutes} minute#{minutes > 1 ? 's' & lengthy = true : ''}, " if minutes > 0 ret += "#{lengthy == true ? 'and ' : }#{ts} second#{ts != 1 ? 's' : }" return ret end # Revives log thread, clears/flushes buffer, and uploads chat logs. def update_logs @client.send_msg "Logging..." @log_mutex.synchronize do if File.exists? File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log") @file = File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "r+") buffer = @file.read @stat_lines = buffer.scan(/\n/).size title = "#{@log_title}#{Time.now.utc.strftime(CATEGORY_TS)}" text = buffer.dup.gsub('<', '&lt;').gsub('>', '&gt;').gsub('_', ' ') # Ideally, this is inside a buffer lock somewhere... text = "#{text}" @client.api.edit title, text, :bot => 1, :minor => 0, :summary => "Updating chat logs. #{@stat_lines} lines added, #{@stat_kicks} kicks, #{@stat_bans} bans reported." else @file = File.open("#{@old_log}", "r") buffer = @file.read @stat_lines = buffer.scan(/\n/).size title = "#{@log_title}#{Time.now.utc.strftime(CATEGORY_TS)}" text = buffer.dup.gsub('<', '&lt;').gsub('>', '&gt;').gsub('_', ' ') # Ideally, this is inside a buffer lock somewhere... text = "#{text}" @client.api.edit title, text, :bot => 1, :minor => 0, :summary => "Updating chat logs. #{@stat_lines} lines added, #{@stat_kicks} kicks, #{@stat_bans} bans reported." end end @old_log = File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log") @client.send_msg "Logs successfully uploaded." end # Acts as a watchdog for the logging thread. def log_thread @log_thread = Thread.new do			while @log_interval > 0 do				sleep @log_interval update_logs end end @log_thread end # Provides a standardized method to kicking so that the bot doesn't kick at the wrong times. def kick(target) return if target.is? :mod if @kickrule == NO_KICK return elsif @kickrule == NO_KICK_WHEN_NO_MODS @client.userlist.each do |user| if user.is? :mod cankick = true end end if cankick == false return end elsif @kickrule == NO_KICK_WHEN_MODS_ON @client.userlist.each do |user| if user.is? :mod return end end end @client.kick(target.name) end # Provides standardized methods for logging. def log_msg(user, message) @log_mutex.synchronize do			message.split(/\n/).each do |line| if /^\/me/.match(line) and message.start_with? '/me' File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')} #{line.gsub(/\/me /, '')}")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')} #{line.gsub(/\/me /, '')}" elsif message.start_with? '/me' File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')} #{line.gsub(/\/me /, '')}")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')} #{line.gsub(/\/me /, '')}" else File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')}: #{line}")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [CHAT] ' + "#{user.log_name.gsub("_", ' ')}: #{line}" end end end end def log_join(user) @log_mutex.synchronize do			File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [JOIN] ' + "#{user.name} has joined the chat.")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [JOIN] ' + "#{user.name} has joined the chat." end end def log_part(user) @log_mutex.synchronize do			File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [QUIT] ' + "#{user.name} has left the chat.")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [QUIT] ' + "#{user.name} has left the chat." end end def log_kick(target, mod) @log_mutex.synchronize do			File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [KICK] ' + "#{target.name} was kicked from chat by #{mod.name}.")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [KICK] ' + "#{target.name} was kicked from chat by #{mod.name}." end end def log_ban(target, mod, time, reason) @log_mutex.synchronize do			File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [CBAN] ' + "#{target.name} was banned from chat by #{mod.name} for #{get_hms(time)}.")} File.open(File.join("logs", "#{Time.now.utc.strftime(CATEGORY_TS)}.log"), "a") {|f| f.write("\n" + Time.now.utc.strftime(MESSAGE_TS) + ' [CBAN] ' + "	[Reason: #{reason}].")} puts Time.now.utc.strftime(MESSAGE_TS) + ' [CBAN] ' + "#{target.name} was banned from chat by #{mod.name} for #{get_hms(time)}." puts Time.now.utc.strftime(MESSAGE_TS) + ' [CBAN] ' + "	[Reason: #{reason}]." end end # Triggered when any message is sent. def onmessage(user, text) # Log the message before anything else. log_msg(user, text) # Dissuade ALL message checking if it is the bot; this will resolve spam warnings. return if user.name == @client.config['user'] # Start the swear detector. if (!!(text =~ @swearregex) == true and (!!(text =~ /^(?:!|\/|\\)(?:x|swearlist|swears|swearcheck)(?:\s|)(|\S*)(?:\s|)(|\S*)(?:\s|)(|\S*)$/is) == false and user.is? :op)) and user.name != @client.config['user'] and !user.is? :mod and @swearcheck == true if !!(text =~ /gemfuck\b/ism) == false @client.send_msg "#{user.name}, please don't swear!" kick(user.name) end end # Start the webchecker. if @webcheck == true websites = text.scan(/http:\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))[\w\-\.,@?^=%&amp;:\~\+#]*[\w\-\@?^=%&amp;~\+#]?|https:\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))[\w\-\.,@?^=%&amp;:\~\+#]*[\w\-\@?^=%&amp;~\+#]?/i).flatten.reject(&:'nil?').uniq websites.each do |url| if !!(url =~ @siteregex) == false res = HTTParty.get("http://api.mywot.com/0.4/public_link_json2?hosts=#{url}/&key=26440f798f13affc273dad8d1f40b43684651373") data = JSON.parse(res) begin cf = data["#{url}"]["4"][0] tw = data["#{url}"]["0"][0] if cf <= 20 and tw <= 20 @client.send_msg("#{user.name}, that website appears to violate the chat rules.") kick(user.name) elsif cf <= 20 @client.send_msg("#{user.name}, that website appears to have adult content on it, which violates our chat rules.") kick(user.name) elsif tw <= 20 @client.send_msg("#{user.name}, that website appears to harbor malware, which violates our chat rules.") kick(user.name) end rescue # do nothing end end end end # Start the spam detector. if @spamlist.has_key? user.name if Time.now.to_i - @spamlist[user.name]['reps'] < 1 @spamlist[user.name]['count'] += 1 if @spamlist[user.name]['count'] > 3 @client.send_msg "#{user.name}, please don't spam!" @spamlist[user.name]['count'] = 1 kick(user.name) end end if @spamlist[user.name]['msg'].length > 4 if @spamlist[user.name]['msg'].uniq.length == 1 @client.send_msg "#{user.name}, please don't spam!" @spamlist[user.name]['msg'].pop @spamlist[user.name]['msg'].unshift(text) kick(user.name) else @spamlist[user.name]['msg'].pop @spamlist[user.name]['msg'].unshift(text) end else @spamlist[user.name]['msg'].unshift(text) end else @spamlist[user.name] = {'reps' => Time.now.to_i, 'count' => 0, 'msg' => [], 'caps' => 0, 'joins' => {'reps' => Time.now.to_i, 'count' => 1}} end # Start the caps detector. caps = text.scan(/([A-Z]{2,})/s) if caps.length > 6 @client.send_msg "#{user.name}, please restrict caps usage to below six words." @spamlist[user.name]['caps'] = 0 else @spamlist[user.name]['caps'] += caps.length end # Calculate caps over time. if @spamlist[user.name]['caps'] > 6 @client.send_msg "#{user.name}, please restrict caps usage across messages to below eight words." @spamlist[user.name]['caps'] = 0 else @spamlist[user.name]['caps'] = 0 end File.open('spam.yml', 'w+') do |f| f.write(@spamlist.to_yaml) end # Check if they are stretching chat. if !!(text =~ /(\S){256,}/is) == true @client.send_msg "#{user.name}, please don't send messages that stretch the chat!" kick(user.name) end # Update the seen setup. @seenlist[user.name.downcase] = Time.now.to_i File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Triggered when a user joins. def onjoin(*data) user = @client.userlist[data[0]['attrs']['name']] # Log the message before anything else. log_join(user) # Little more steps, but dissuade all processing. if user.name == @client.config['user'] @client.send_msg "pearl.rb v#{VERSION} is now online." if @client.config['variables']['silent'] == true or @silent == true @client.away end return end # Start the spam detector. if @spamlist.has_key? user.name if Time.now.to_f - @spamlist[user.name]['joins']['reps'] < 2 @spamlist[user.name]['joins']['count'] += 1 if @spamlist[user.name]['joins']['count'] > 1 @client.send_msg "#{user.name}, please check your internet connection!" @spamlist[user.name]['joins']['count'] = 0 end end else @spamlist[user.name] = {'reps' => Time.now.to_i, 'count' => 0, 'msg' => [], 'caps' => 0, 'joins' => {'reps' => Time.now.to_i, 'count' => 1}} end File.open('spam.yml', 'w+') do |f| f.write(@spamlist.to_yaml) end # Check if they have an inadequate amount of edits. if @editlimit > user.edits sleep 1 @client.send_msg "#{user.name}, you need at least #{@editlimit == 1 ? "#{@editlimit} edit" : "#{@editlimit} edits"} to join chat, please come back when you've achieved that amount." kick(user.name) return end
 * 1) Generate the class.

# Update the seen setup. @seenlist[user.name.downcase] = Time.now.to_i File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Triggered when a user leaves. def onpart(*data) user = @client.userlist[data[0]['attrs']['name']] # Log the message before anything else. log_part(user) # Dissuade message processing for bot. return if user.name == @client.config['user'] # Start the spam detector. if @spamlist.has_key? user.name @spamlist[user.name]['joins']['count'] -= 1 else @spamlist[user.name] = {'reps' => Time.now.to_i, 'count' => 0, 'msg' => [], 'caps' => 0, 'joins' => {'reps' => Time.now.to_i, 'count' => 1}} end File.open('spam.yml', 'w+') do |f| f.write(@spamlist.to_yaml) end # Update the seen setup. @seenlist[user.name.downcase] = Time.now.to_i File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Triggered when a user is kicked. def onkick(*data) user = @client.userlist[data[0]['attrs']['kickedUserName']] mod = @client.userlist[data[0]['attrs']['moderatorName']] # Log the message before anything else. log_kick(user, mod) # Dissuade message processing for bot. return if user.name == @client.config['user'] # Update the seen setup. @seenlist[user.name.downcase] = Time.now.to_i File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Triggered when a user is banned. def onban(*data) user = @client.userlist[data[0]['attrs']['kickedUserName']] mod = @client.userlist[data[0]['attrs']['moderatorName']] time = data[0]['attrs']['time'].to_i reason = data[0]['attrs']['reason'] # Log the message before anything else. log_ban(user, mod, time, reason) # Dissuade message processing for bot. return if user.name == @client.config['user'] # Check if informban is on. if @informban == true @client.send_msg "#{user.name} was banned for #{get_hms(time)}, reason: #{reason}" end # Update the seen setup. @seenlist[user.name.downcase] = Time.now.to_i File.open('seen.yml', 'w+') do |f| f.write(@seenlist.to_yaml) end end # Triggered by single-letter commands. def commands(user, command, arg1, arg2, arg3) # OPERATOR ONLY COMMANDS: these affect the way the bot works, or utilize an abusable task. if user.is? :op if @client.userlist[@client.config["user"]].is? :mod if (command == "k" or command == "kick") # Kick command - kicks a user. if arg3 == "rule" if arg2 == "NO_KICK" or arg2 == "0" @client.send_msg "The bot will cease the ability to kick altogether." @kickrule = NO_KICK @client.config["kickrule"] = NO_KICK elsif arg2 == "NO_KICK_WHEN_NO_MODS" or arg2 == "1" @client.send_msg "The bot will only kick when no mods are in chat." @kickrule = NO_KICK_WHEN_NO_MODS @client.config["kickrule"] = NO_KICK_WHEN_NO_MODS elsif arg2 == "NO_KICK_WHEN_MODS_ON" or arg2 == "2" @client.send_msg "The bot will only kick when there are mods in chat." @kickrule = NO_KICK_WHEN_MODS_ON @client.config["kickrule"] = NO_KICK_WHEN_MODS_ON elsif arg2 == "NO_KICK_NEVER" or arg2 == "3" @client.send_msg "The bot will always kick." @kickrule = NO_KICK_NEVER @client.config["kickrule"] = NO_KICK_NEVER else @client.send_msg "Unknown value: #{arg2}; accepted values: NO_KICK, NO_KICK_WHEN_NO_MODS, NO_KICK_WHEN_MODS_ON, NO_KICK_NEVER" end @client.save_config else target = arg3.gsub("_", ' ') targets = target.split(/\s*,\s*/) targets.each do |person| if @client.userlist[person].is? :mod @client.send_msg "#{person} is a mod and can not be kicked!" else @client.send_msg "Kicking #{target}." @client.kick(target) end end end end if (command == "b" or command == "ban") # Ban command - bans a user from chat. target = arg3.gsub("_", ' ') if arg2 == "infinite" or arg2 == "forever" or arg2 == "perma" or arg2 == "indefinite" time = "31536000000".to_i elsif arg2 == "unban" or arg2 == "end" time = "0".to_i else if arg2.end_with? "s" time = arg1.to_i elsif arg2.end_with? "m" time = arg1.to_i * 60 elsif arg2.end_with? "h" time = arg1.to_i * 3600 elsif arg2.end_with? "d" time = arg1.to_i * 86400 elsif arg2.end_with? "w" time = arg1.to_i * 604800 elsif arg2.end_with? "M" time = arg1.to_i * 2592000 elsif arg2.end_with? "y" time = arg1.to_i * 31556926 else time = arg1.to_i * 3600 end end targets = target.split(/\s*,\s*/) targets.each do |person| if @client.userlist[person].is? :mod @client.send_msg "#{person} is a mod and can not be banned!" else @client.send_msg "#{time == 0 ? "Unbanning #{target}." : "Banning #{target} for #{get_hms(time)}."}" @client.ban(person, time, "#{time == 0 ? "Unbanned by #{user.name} via bot." : "Banned by #{user.name} via bot for immediate policy infractions."}") end end end if (command == "u" or command == "unban") # Unban command - unbans a user. target = arg3.gsub("_", ' ') targets = target.split(/\s*,\s*/) targets.each do |person| @client.send_msg "Unbanning #{target}." @client.ban(person, 0, "Unbanned by #{user.name} via bot.") end end end if (command == "l" or command == "log") # Log command, logs to wiki. if arg3 == "" or arg3 == "chat" thr = Thread.new do						update_logs end else if arg2 == "interval" if arg3.end_with? "s" time = arg3.to_i elsif arg3.end_with? "m" time = arg3.to_i * 60 elsif arg3.end_with? "h" time = arg3.to_i * 3600 elsif arg3.end_with? "d" time = arg3.to_i * 86400 elsif arg3.end_with? "w" time = arg3.to_i * 604800 elsif arg3.end_with? "M" time = arg3.to_i * 2592000 elsif arg3.end_with? "y" time = arg3.to_i * 31556926 else time = arg3.to_i * 60 end @client.send_msg "Bot will now upload logs every #{get_hms(time)}." @log_interval = time @client.config["logging"]["interval"] == @log_interval @client.save_config else @client.send_msg "Unknown value: #{arg3}" end end end if (command == "r" or command == "restart") # Restart/reboot command - restarts the bot. if user.is? :dev @client.send_msg "Restarting." else @client.send_msg "Please note that the restart command is used generally for the purpose of updating codes and not for fixing any errors." @client.send_msg "If you think you have found an error in the bot, please take it directly to Akrivus instead of enacting potential abuse of the restart command." end system("ruby start.rb") @client.quit end if (command == "q" or command == "quit" or command == "stop") # Stop command - stops the bot. if user.is? :dev @client.send_msg "Stopping." @client.quit else @client.send_msg "Due to hard-coded security protocols, the quit command can only be used by Akrivus." end end if (command == "x" or command == "swearlist" or command == "swears" or command == "swearcheck") # Swear list entry command - adds or removes a new swear to the list. if arg3 == "on" or arg3 == "off" or arg3 == "true" or arg3 == "false" if arg3 == "on" or arg3 == "true" @client.send_msg "Swearchecking on." @client.config['variables']['swearcheck'] == true @client.save_config elsif arg3 == "off" or arg3 == "false" @client.send_msg "Swearchecking off." @client.config['variables']['swearcheck'] == false @client.save_config else @client.send_msg "Unknown value: #{arg3}" end else if arg2 == "-" or arg2 == "remove" or arg2 == "del" @client.send_msg "Removed #{arg3.gsub('\\', '')} from the swear list." @swearlist['swears'].delete(arg3.to_s) elsif arg2 == "+" or arg2 == "new" or arg2 == "add" @client.send_msg "Added #{arg3.gsub('\\', '')} to the swear list." @swearlist['swears'].push(arg3.to_s) elsif arg1 == "sites" or arg1 == "sitelist" if arg2 == "-" or arg2 == "remove" or arg2 == "del" @client.send_msg "Removed #{arg3.gsub(/http(?:s):\/\//, '')} from the site whitelist." @sitelist['sites'].delete(arg3.gsub(/http(?:s):\/\//, '')) elsif arg2 == "+" or arg2 == "new" or arg2 == "add" @client.send_msg "Added #{arg3.gsub(/http(?:s):\/\//, '')} from the site whitelist." @sitelist['sites'].push(arg3.gsub(/http(?:s):\/\//, '')) end # Write the new swearlist. File.open('sites.yml', 'w+') do |f| f.write(@sitelist.to_yaml) end # Set up the new swear list. @siteregex = "" first = true @sitelist['sites'].each do |site| if first == true first = false else @siteregex = @siteregex + "|" end @siteregex = @siteregex + site end @siteregex = "(" + @siteregex + ")" @siteregex = %r[#{@siteregex}]ism end # Write the new swearlist. File.open('swears.yml', 'w+') do |f| f.write(@swearlist.to_yaml) end # Set up the new swear list. @swearregex = "" first = true @swearlist['swears'].each do |swear| if first == true first = false else @swearregex = @swearregex + "|" end swear = swear.gsub("\\", "\\b") @swearregex = @swearregex + swear end @swearregex = "(" + @swearregex + ")" @swearregex = %r[#{@swearregex}]ism end end if (command == "editlimit") # Editlimit setter, sets the edit limit. if (arg3 == "") @client.send_msg "The edit limit is current #{@editlimit}, to change use the same command with an integer value (ex: !editlimit [none|1|etc])" else if (arg3 == "off" or arg3 == "none") @editlimit == 0 end @editlimit = arg3.to_i @client.send_msg "Edit limit now set to #{@editlimit}, any users below this amount will be warned or kicked." @client.config['variables']['editlimit'] = @editlimit @client.save_config end end if ((command == "f" or command == "find" or command == "s" or command == "seen") and (arg3 == "on" or arg3 == "off" or arg3 == "true" or arg3 == "false")) # Seen command - looks for the last time a user joined chat. if arg3 == "true" or arg3 == "on" @client.send_msg "Seen on." @seen = true elsif arg3 == "false" or arg3 == "off" @client.send_msg "Seen off." @seen = false else @client.send_msg "Unknown value: #{arg3}" end @client.config['variables']['seen'] = @seen @client.save_config end if ((command == "w" or command == "webcheck" or command == "checksite") and (arg3 == "on" or arg3 == "off" or arg3 == "true" or arg3 == "false")) # Website checking command - checks website for safety. if arg3 == "true" or arg3 == "on" @client.send_msg "Webcheck on." @webcheck = true elsif arg3 == "false" or arg3 == "off" @client.send_msg "Webcheck off." @webcheck = false else @client.send_msg "Unknown value: #{arg3}" end @client.config['variables']['webcheck'] = @webcheck @client.save_config end if (command == "silent") # Silence command - tells the bot to not speak. if arg3 == "true" or arg3 == "on" @client.send_msg "Silent mode on." @client.away @silent = true elsif arg3 == "false" or arg3 == "off" @client.send_msg "Silent mode off." @client.here @silent = false else @client.send_msg "Unknown value: #{arg3}" end @client.config['variables']['silent'] = @silent @client.save_config end end if ((@silent == false) or (@silent == true and user.is? :op)) if (command == "c" or command == "commands" or command == "help") # Commands-list command - gives a link to the bot's documentaion. @client.send_msg "A list of all current commands can be found here." end if (command == "e" or command == "emotes" or command == "emoticons") # Emote-list command - gives a list of emotions on MediaWiki:Emoticon. @client.send_msg "A list of all emotes and their keys can be found here." end if (command == "f" or command == "find" or command == "s" or command == "seen") and @seen == true # Seen command - looks for the last time a user joined chat. if @seenlist.has_key? arg3.downcase.gsub('_', ' ') @client.send_msg "#{user.name}, I last saw #{arg3} in chat about #{get_hms(Time.now.to_i - @seenlist[arg3.downcase.gsub('_', ' ')])} ago." else @client.send_msg "#{user.name}, I haven't seen #{arg3} in chat." end end if (command == "i" or command == "info" or command == "bot") # Info command - informs the end user of the bot. @client.send_msg "pearl.rb v#{VERSION}, online for #{get_hms(Time.now.to_i - @stat_time)}, ran by Akrivus." end if (command == "stats" or command == "kicks" or command == "bans" or command == "joins" or command == "leaves") # Stats command - informs the end user of bot stats. @client.send_msg "In the last #{get_hms(Time.now.to_i - @stat_time)}, #{@stat_kicks} kicks, #{@stat_bans} bans, #{@stat_joins} joins, and #{@stat_leaves} leaves have been recorded." end end end end