forestbot/bot.rb

117 lines
2.2 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require 'cinch'
require 'cinch-dicebag'
require 'net/http'
require 'uri'
require 'json'
require 'formdata'
require 'nokogiri'
require 'digest'
require 'yaml'
require_relative 'plugins/link_info'
require_relative 'plugins/help'
require_relative 'plugins/questbook'
def translit (text)
table = {
"a"=>["А","а"],
"ä"=>["э"],
"b"=>["Б","б"],
"c"=>["Ц", "ц"],
"ch"=>["Ч", "ч"],
"d"=>["д"],
"e"=>["е"],
"j" => ["й"],
"f"=>["ф"],
"g"=>["г"],
"h"=>["х"],
"i"=>["и"],
"ja"=>["я"],
"ju"=>["ю"],
"k"=>["к"],
"l"=>["л"],
"m"=>["м"],
"n"=>["н"],
"o"=>["о"],
"ö"=>["ё"],
"p"=>["п"],
"r"=>["р"],
"s"=>["з", "с"],
"t"=>["т"],
"u"=>["у"],
"ü"=>["ю"],
"v"=>["ф"],
"w"=>["в"],
"x"=>["кс"],
"y"=>["ы"],
"sch"=>["ш"],
"schtsch"=>["щ"],
"z"=>["ж"],
"zh"=>["ж"],
"zsch"=>["ч"],
"tzsch"=>["чш"],
"'"=>["ь"],
"q"=>["я"]
}
map = table.sort_by {|k,_| k.to_str.length }.reverse
map.each do |translit_key, translit_value|
text.gsub!(translit_key.capitalize, translit_value.first)
text.gsub!(translit_key, translit_value.last)
end
text
end
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.forestnet.org"
c.port = 6667
c.channels = [
"#fireurq",
"#urq",
"#instead",
"#qsp",
"#ifrus",
"#questbook"
]
c.nick = 'РобоВера'
c.plugins.plugins = [
Cinch::Plugins::Dicebag,
Cinch::Help,
Cinch::LinkInfo,
QuestBook
]
c.plugins.options[Cinch::LinkInfo] = {
:blacklist => [/\.xz$/i, /\.zip$/i, /\.rar$/i],
:no_description => true,
}
end
on :message do |m|
if m.user.nick == 'MAlischka' or m.user.nick == 'MA' or m.user.nick == 'figwama' then
m.reply( translit(m.message) )
end
end
on :message, /^!translit (.+)/ do |m, query|
m.reply translit(query)
end
end
bot.loggers.level = :info
class QuestBookChat
def initialize(bot)
@bot = bot
end
def start
while true
sleep 5
@bot.handlers.dispatch(:questbook)
end
end
end
Thread.new {
QuestBookChat.new(bot).start
}
bot.start