activerpg/rpgqui.rb

127 lines
3.6 KiB
Ruby

require 'cinch'
load "active_rpg.rb"
def fix_nick(n)
return n[0] + "\uFEFF" + n[1,n.length]
end
# Clean up all nicks in the responses
def fix_nicks(response, users)
fixed_response = response
users.keys.each do |u|
split_response = fixed_response.split(u.nick)
fixed_response = split_response.join(fix_nick(u.nick))
end
return fixed_response
end
bot = Cinch::Bot.new do
# Set up the data store here...
$w = ActiveRpg.new(25, 'libera-rpg_new')
$output_channel = "#active_rpg"
$intro_message = "Hi! I'm a bot that runs a passively active RPG game. Please join " +
$output_channel + " to track progress"
configure do |c|
c.server = "irc.libera.chat"
c.user = "Monqui"
c.password = "tbmsn"
c.nick = "rpgqui"
c.delay_joins = 15
c.channels = ["#bakedbeans", "#sconesandcream fatjoints", $output_channel]
c.timeouts.connect = 30
end
on :join do |m|
if m.channel != $output_channel then
m.reply $intro_message + ", or say '!help' for a list of commands!"
end
end
on :message, ".bots" do |m|
m.reply "rEpOrtInG iN! [ruby] Lmao!"
end
on :message, /^(.*)$/ do |m, line|
synchronize(:rpg) do
if line[0] != "!" then
res = $w.take_turn(m.user.nick, line)
if res != "" and res != nil then
fixed_response = fix_nicks(res, m.channel.users)
self.bot.channel_list.find($output_channel).send(fixed_response)
end
end
end
end
on :message, /^!help$/ do |m|
response = $intro_message
response = response + ", or use the following commands to get more info!\n"
response = response + "!rpg - personal user stats; !critters - list entities in the world; "
response = response + "!leaderboard - ugly printout of all user stats; "
response = response + "!rpgbet - bet against another user for xp! "
response = response + "(\"!rpgbet [target_player] [amount]\")"
m.reply response
end
on :message, /^!rpg$/ do |m|
synchronize(:rpg) do
mc = $w.get_mc()
u = mc.collection.find({"type" => :player, "name" => m.user.nick}).first
pet = mc.collection.find({"type" => :boss, "spawned_by" => m.user.nick}).first
out = m.user.nick + " currently has " + u['exp'].to_s + "xp at " + u['location'].inspect + "! "
if pet != nil then
out = out + "Their pet, the " + pet["name"] + " is chilling out at " + pet['location'].inspect + " "
out = out + "with " + pet["exp"].to_s + " points of power!"
end
m.reply out
end
end
on :message, /^!critters$/ do |m|
synchronize(:rpg) do
mc = $w.get_mc()
out = "Critters crittering around: " + mc.collection().find({"type" => :monster}).count.to_s
out = out + "\n"
out = out + "Bosses bossing around: " + mc.collection().find({"type" => :boss}).count.to_s
out = out + "\n"
out = out + "Events eventing around: " + mc.collection().find({"type" => :random_event}).count.to_s
m.reply out
end
end
on :message, /^!leaderboard$/ do |m|
synchronize(:rpg) do
mc = $w.get_mc()
users = mc.collection.find({"type" => "player"})
sorted = users.to_a.sort_by{|i| i['exp']}
sorted.reverse!
out_str = ""
sorted.each do |i|
out_str = out_str + fix_nick(i['name']) + i['location'].inspect + ": " + i['exp'].to_s + '; '
end
m.reply(out_str)
end
end
on :message, /^!rpgbet (\S*) (\d*)$/ do |m, target, amount|
bets = $w.get_bets()
# m.reply m.user.nick + " wants to post up a bet of " + amount.to_s + " against " + target
m.reply bets.place_bet(m.user.nick, target, amount.to_i)
end
end
bot.start