X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Flart.rb;h=aeaad7333246153b731d6e613f1e60ac0ba1d32a;hb=052217de30c59206d7025b582d4604557a747470;hp=9b627fc5ad836c469a93e1e51e26bd1bb578aad1;hpb=4fd0126d6dd2254a43436045db855393b8bb6ad3;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/lart.rb b/data/rbot/plugins/lart.rb index 9b627fc5..aeaad733 100644 --- a/data/rbot/plugins/lart.rb +++ b/data/rbot/plugins/lart.rb @@ -1,24 +1,29 @@ -# Original Author: -# Michael Brailsford -# aka brailsmt -# Author: Giuseppe "Oblomov" Bilotta -# Purpose: Provide for humorous larts and praises -# Original Copyright: -# 2002 Michael Brailsford. All rights reserved. -# Copyright: 2006 Giuseppe Bilotta. All rights reserved. -# License: This plugin is licensed under the BSD license. The terms of -# which follow. +#-- vim:sw=2:et +#++ # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: +# :title: lart/praise plugin for rbot # -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. +# Author:: Michael Brailsford aka brailsmt +# Author:: Giuseppe "Oblomov" Bilotta # -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. +# Copyright:: (C) 2002 Michael Brailsford. All rights reserved. +# Copyright:: (C) 2006 Giuseppe Bilotta. All rights reserved. +# +# License:: This plugin is licensed under the BSD license. The terms of +# which follow. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Purpose:: Provide for humorous larts and praises class LartPlugin < Plugin @@ -36,12 +41,12 @@ class LartPlugin < Plugin # We may be on an old installation, so on the first run read non-language-specific larts unless defined?(@oldlart) - @oldlart = "#{@bot.botclass}/lart/larts" - @oldpraise = "#{@bot.botclass}/lart/praise" + @oldlart = datafile 'larts' + @oldpraise = datafile 'praise' end - @lartfile.replace "#{@bot.botclass}/lart/larts-#{lang}" - @praisefile.replace "#{@bot.botclass}/lart/praises-#{lang}" + @lartfile.replace(datafile("larts-#{lang}")) + @praisefile.replace(datafile("praises-#{lang}")) @larts.clear @praises.clear if File.exists? @lartfile @@ -67,8 +72,7 @@ class LartPlugin < Plugin def save return unless @changed - Dir.mkdir("#{@bot.botclass}/lart") if not FileTest.directory? "#{@bot.botclass}/lart" - # TODO implement safe saving here too + Dir.mkdir(datafile) unless FileTest.directory? datafile Utils.safe_save(@lartfile) { |file| file.puts @larts } @@ -90,6 +94,9 @@ class LartPlugin < Plugin end who = params[:who].to_s reason = params[:why] + if who == "me" + who = m.sourcenick + end if who == @bot.nick who = m.sourcenick reason = "for trying to make me lart myself" @@ -108,7 +115,8 @@ class LartPlugin < Plugin end who = params[:who].to_s reason = params[:why] - if who == m.sourcenick + if who == m.sourcenick || who == "me" + params[:who] = m.sourcenick params[:why] = "for praising himself" handle_lart(m, params) return @@ -120,29 +128,49 @@ class LartPlugin < Plugin end def handle_addlart(m, params) - @larts << params[:lart] + @larts << params[:lart].to_s @changed = true m.okay end def handle_rmlart(m, params) - @larts.delete params[:lart] + @larts.delete params[:lart].to_s @changed = true m.okay end + def handle_listlart(m, params) + rx = Regexp.new(params[:lart].to_s, true) + list = @larts.grep(rx) + unless list.empty? + m.reply list.join(" | "), :split_at => /\s+\|\s+/ + else + m.reply "no lart found matching #{params[:lart]}" + end + end + def handle_addpraise(m, params) - @praises << params[:praise] + @praises << params[:praise].to_s @changed = true m.okay end def handle_rmpraise(m, params) - @praises.delete params[:praise] + @praises.delete params[:praise].to_s @changed = true m.okay end + def handle_listpraise(m, params) + rx = Regexp.new(params[:praise].to_s, true) + list = @praises.grep(rx) + unless list.empty? + m.reply list.join(" | "), :split_at => /\s+\|\s+/ + else + m.reply "no praise found matching #{params[:praise]}" + end + end + # The following are utils for larts/praises def replace_who(msg, nick) msg.gsub(//i, "#{nick}") @@ -164,3 +192,6 @@ plugin.map "addpraise *praise", :action => :handle_addpraise plugin.map "rmlart *lart", :action => :handle_rmlart plugin.map "rmpraise *praise", :action => :handle_rmpraise + +plugin.map "listlart *lart", :action => :handle_listlart +plugin.map "listpraise *praise", :action => :handle_listpraise