- command = m.message.dup
- if(m.address? && m.private?)
- case command
- when (/^addquote\s+(#\S+)\s+(.*)/)
- channel = $1
- quote = $2
- if(@bot.auth.allow?("addquote", m.source, m.replyto))
- if(channel =~ /^#/)
- num = addquote(m.source, channel, quote)
- m.reply "added the quote (##{num})"
- end
- end
- when (/^getquote\s+(#\S+)$/)
- channel = $1
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^getquote\s+(#\S+)\s+(\d+)$/)
- channel = $1
- num = $2.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel, num)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^whoquote\s+(#\S+)\s+(\d+)$/)
- channel = $1
- num = $2.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel, num)
- if(quote)
- m.reply "quote #{quote.num} added by #{quote.source}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^whenquote\s+(#\S+)\s+(\d+)$/)
- channel = $1
- num = $2.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel, num)
- if(quote)
- m.reply "quote #{quote.num} added on #{quote.date}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^topicquote\s+(#\S+)$/)
- channel = $1
- if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel)
- if(quote)
- @bot.topic channel, "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^topicquote\s+(#\S+)\s+(\d+)$/)
- channel = $1
- num = $2.to_i
- if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, channel, num)
- if(quote)
- @bot.topic channel, "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^delquote\s+(#\S+)\s+(\d+)$/)
- channel = $1
- num = $2.to_i
- if(@bot.auth.allow?("delquote", m.source, m.replyto))
- if(delquote(channel, num))
- m.okay
- else
- m.reply "quote not found!"
- end
- end
- when (/^searchquote\s+(#\S+)\s+(.*)$/)
- channel = $1
- reg = $2
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = searchquote(m.source, channel, reg)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^countquote$/)
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- total = countquote(m.source)
- m.reply "#{total} quotes"
- end
- when (/^countquote\s+(#\S+)\s*(.*)$/)
- channel = $1
- reg = $2
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- total = countquote(m.source, channel, reg)
- if(reg.length > 0)
- m.reply "#{total} quotes match: #{reg}"
- else
- m.reply "#{total} quotes"
- end
- end
- end
- elsif (m.address? || (@bot.config["QUOTE_LISTEN"] && command.gsub!(/^!/, "")))
- case command
- when (/^addquote\s+(.+)/)
- if(@bot.auth.allow?("addquote", m.source, m.replyto))
- num = addquote(m.source, m.target, $1)
- m.reply "added the quote (##{num})"
- end
- when (/^getquote$/)
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "no quotes found!"
- end
- end
- when (/^getquote\s+(\d+)$/)
- num = $1.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^whenquote\s+(\d+)$/)
- num = $1.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
- if(quote)
- m.reply "quote #{quote.num} added on #{quote.date}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^whoquote\s+(\d+)$/)
- num = $1.to_i
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
- if(quote)
- m.reply "quote #{quote.num} added by #{quote.source}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^topicquote$/)
- if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target)
- if(quote)
- @bot.topic m.target, "[#{quote.num}] #{quote.quote}"
- else
- m.reply "no quotes found!"
- end
- end
- when (/^topicquote\s+(\d+)$/)
- num = $1.to_i
- if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
- if(quote)
- @bot.topic m.target, "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^delquote\s+(\d+)$/)
- num = $1.to_i
- if(@bot.auth.allow?("delquote", m.source, m.replyto))
- if(delquote(m.target, num))
- m.okay
- else
- m.reply "quote not found!"
- end
- end
- when (/^searchquote\s+(.*)$/)
- reg = $1
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = searchquote(m.source, m.target, reg)
- if(quote)
- m.reply "[#{quote.num}] #{quote.quote}"
- else
- m.reply "quote not found!"
- end
- end
- when (/^countquote(?:\s+(.*))?$/)
- reg = $1
- if(@bot.auth.allow?("getquote", m.source, m.replyto))
- total = countquote(m.source, m.target, reg)
- if(reg && reg.length > 0)
- m.reply "#{total} quotes match: #{reg}"
- else
- m.reply "#{total} quotes"
- end
- end
- end
+ def cmd_addquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ quote = p[:quote].to_s
+ num = addquote(m.source, channel, quote)
+ m.reply _("added the quote (#%{num})") % { :num => num }
+ end
+
+ def cmd_delquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ num = p[:num].to_i
+ if delquote(channel, num)
+ m.okay
+ else
+ m.reply _("quote not found!")
+ end
+ end
+
+ def cmd_getquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ num = p[:num] ? p[:num].to_i : nil
+ quote, total = getquote(m.source, channel, num)
+ if quote
+ m.reply _("[%{num}] %{quote}") % {
+ :num => quote.num,
+ :quote => quote.quote
+ }
+ else
+ m.reply _("quote not found!")
+ end
+ end
+
+ def cmd_whoquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ num = p[:num] ? p[:num].to_i : nil
+ quote, total = getquote(m.source, channel, num)
+ if quote
+ m.reply _("quote %{num} added by %{source}") % {
+ :num => quote.num,
+ :source => quote.source
+ }
+ else
+ m.reply _("quote not found!")
+ end
+ end
+
+ def cmd_whenquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ num = p[:num] ? p[:num].to_i : nil
+ quote, total = getquote(m.source, channel, num)
+ if quote
+ m.reply _("quote %{num} added on %{date}") % {
+ :num => quote.num,
+ :date => quote.date
+ }
+ else
+ m.reply _("quote not found!")
+ end
+ end
+
+ def cmd_searchquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ reg = p[:reg].to_s
+ quote, total = searchquote(m.source, channel, reg)
+ if quote
+ m.reply _("[%{num}] %{quote}") % {
+ :num => quote.num,
+ :quote => quote.quote
+ }
+ else
+ m.reply _("quote not found!")
+ end
+ end
+
+ def cmd_countquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ reg = p[:reg] ? p[:reg].to_s : nil
+ total = countquote(m.source, channel, reg)
+ if reg.length > 0
+ m.reply _("%{total} quotes matching %{reg}") % {
+ :total => total,
+ :reg => reg
+ }
+ else
+ m.reply _("%{total} quotes") % { :total => total }
+ end
+ end
+
+ def cmd_topicquote(m, p)
+ channel = p[:channel] || m.channel.to_s
+ num = p[:num] ? p[:num].to_i : nil
+ quote, total = getquote(m.source, channel, num)
+ if quote
+ @bot.topic channel, _("[%{num}] %{quote}") % {
+ :num => quote.num,
+ :quote => quote.quote
+ }
+ else
+ m.reply _("quote not found!")