diff --git a/config.yaml b/config.yaml index 23685dd..29cabf5 100644 --- a/config.yaml +++ b/config.yaml @@ -2,6 +2,6 @@ config: server: irc.server.tld port: 6667 nick: default_nickname - channels: ['#put, '#your', '#channels', "#here"] + channels: ['#put', '#your', '#channels', "#here"] realname: default_realname password: password diff --git a/mobot.rb b/mobot.rb index 2780e44..8868eff 100644 --- a/mobot.rb +++ b/mobot.rb @@ -7,18 +7,23 @@ #Load config using YAML config = YAML.load_file("config.yaml") - #Global database accessible by all threads, technically a problem, but honestly what are the chances? $members = [] +$admins = [] $missions = [] +if !config.key? "admins" + config["admins"] = config.fetch( "admins", [] ) +end + +$admins.concat config["admins"] + #Main bot definition mobot = Cinch::Bot.new do #Holds threads created by methods - mostly timers threads = [] - #Should be called whenever the database is changed for any reason def update_db(cont) db = File.open('./database', 'w') @@ -109,67 +114,67 @@ def daily_reset() def mission_reset() @mission = false end - def buy(item, recipient, m) - if item == "kick" - if @credits > 999 - @credits = @credits - 1000 - m.channel.kick(recipient) - val = "User kicked!" - else - val = "You need 1000 credits to kick someone!" - end - end - if item == "devoice" - if @credits > 1999 - @credits = @credits - 2000 - m.channel.devoice(recipient) - val = "User devoiced!" - else - val = "You need 2000 credits to devoice someone!" + def buy(item, recipient, m) + if item == "kick" + if @credits > 999 + @credits = @credits - 1000 + m.channel.kick(recipient) + val = "User kicked!" + else + val = "You need 1000 credits to kick someone!" + end + end + if item == "devoice" + if @credits > 1999 + @credits = @credits - 2000 + m.channel.devoice(recipient) + val = "User devoiced!" + else + val = "You need 2000 credits to devoice someone!" + end + end + if item == "DEX" + amount = 450 + 50 * @dex + if @credits > amount - 1 + @credits = @credits - amount + @dex = @dex + 1 + val = "DEX upgraded! Your DEX is now #{@dex}!" + else + val = "You need #{amount} credits to upgrade your DEX!" + end end + if item == "INT" + amount = 450 + 50 * @int + if @credits > amount - 1 + @credits = @credits - amount + @int = @int + 1 + val = "INT upgraded! Your INT is now #{@int}!" + else + val = "You need #{amount} credits to upgrade your INT!" + end end - if item == "DEX" - amount = 450 + 50 * @dex - if @credits > amount - 1 - @credits = @credits - amount - @dex = @dex + 1 - val = "DEX upgraded! Your DEX is now #{@dex}!" - else - val = "You need #{amount} credits to upgrade your DEX!" - end - end - if item == "INT" - amount = 450 + 50 * @int - if @credits > amount - 1 - @credits = @credits - amount - @int = @int + 1 - val = "INT upgraded! Your INT is now #{@int}!" - else - val = "You need #{amount} credits to upgrade your INT!" - end - end - if item == "STR" - amount = 450 + 50 * @str - if @credits > amount - 1 - @credits = @credits - amount - @str = @str + 1 - val = "STR upgraded! Your STR is now #{@str}!" - else - val = "You need #{amount} credits to upgrade your STR!" + if item == "STR" + amount = 450 + 50 * @str + if @credits > amount - 1 + @credits = @credits - amount + @str = @str + 1 + val = "STR upgraded! Your STR is now #{@str}!" + else + val = "You need #{amount} credits to upgrade your STR!" + end end - end - if item == "LCK" - amount = 450 + 50 * @lck - if @credits > amount - 1 - @credits = @credits - amount - @lck = @lck + 1 - val = "LCK upgraded! Your LCK is now #{@lck}!" - else - val = "You need #{amount} credits to upgrade your LCK!" + if item == "LCK" + amount = 450 + 50 * @lck + if @credits > amount - 1 + @credits = @credits - amount + @lck = @lck + 1 + val = "LCK upgraded! Your LCK is now #{@lck}!" + else + val = "You need #{amount} credits to upgrade your LCK!" + end end - end - val - end + val + end end @@ -188,7 +193,7 @@ def get_user(user, mem) begin $members = Marshal.load File.read('./database') rescue - puts "Failed to load database!" + puts "Failed to load database!" end #Initial Bot Config @@ -202,12 +207,11 @@ def get_user(user, mem) c.delay_joins = :identified c.plugins.plugins = [Cinch::Plugins::Identify] c.plugins.options[Cinch::Plugins::Identify] = { - :password => config['config']['password'], - :type => :nickserv, - } + :password => config['config']['password'], + :type => :nickserv, + } end - #$missions.push(Mission.new("The Jade Figurine - Lysana & Undertaker", "DEX", 70, "You find a rare jade figurine that belongs to a Chinese politician. He send a group of ninjas to hunt you down and reclaim it.", "Despite all odds your agile maneuvering is enough to allude the ninjas. Impressed, they report back to their leader, and you are allowed to keep the figurine.", "Unable to escape the ninjas, you are forced to leave the figurine behind. As you do, the ninjas stop their chase, and you come home to binge on healbot syringes, licking your wounds on the close escape.")) $missions.concat(loadMissions()) $members.each do |i| @@ -225,8 +229,8 @@ def get_user(user, mem) on :message, /^SEND (#.+)/ do |m, args| lst = args.split(' ') - contents = lst[1..lst.length].join(' ') - Channel(lst[0]).send(contents) + contents = lst[1..lst.length].join(' ') + Channel(lst[0]).send(contents) end on :message, /^MESSAGE (.+)/ do |m, args| @@ -247,9 +251,9 @@ def get_user(user, mem) end on :message, /^.credits/ do |m| - lst = m.message.split(' ') - if lst.length > 1 - m.reply mobot.get_user(lst[1], $members).credits + lst = m.message.split(' ') + if lst.length > 1 + m.reply mobot.get_user(lst[1], $members).credits else m.reply mobot.get_user(m.user.to_s, $members).credits end @@ -397,16 +401,32 @@ def get_user(user, mem) on :message, /^.cmod (.+)/ do |m, arg| lst = arg.split(' ') - amount = lst[0] - recipient = lst[1] - if m.user.to_s == 'varzeki' - user = mobot.get_user(recipient, $members) - user.credits = user.credits + amount.to_i - m.reply "User credited!" - mobot.update_db($members) - else - m.reply "You don't have permission to do that!" - end + amount = lst[0] + recipient = lst[1] + if $admins.include? m.user.to_s + user = mobot.get_user(recipient, $members) + user.credits = user.credits + amount.to_i + m.reply "User credited!" + mobot.update_db($members) + else + m.reply "You don't have permission to do that!" + end + end + + on :message, /^.admin (.+)/ do |m, arg| + lst = arg.split(' ') + recipient = lst[0] + if (!config["admins"].include? recipient) && ($admins.include? m.user.to_s) + if $admins.include? recipient + $admins.delete_at($admins.find_index(recipient)) + m.reply "#{recipient} was removed from admins." + else + $admins.push(recipient) + m.reply "#{recipient} was added as an admin." + end + else + m.reply "You don't have permission to do that!" + end end on :message, /^.crew (.+)/ do |m, arg|