|
@@ -7,6 +7,9 @@ require 'securerandom'
|
|
|
require 'net/http'
|
|
|
require 'json'
|
|
|
require 'youtube-dl.rb'
|
|
|
+require 'sqlite3'
|
|
|
+
|
|
|
+db = SQLite3::Database.open 'tankbot.db'
|
|
|
|
|
|
$settings = YAML.load(File.read "config.yaml")['settings']
|
|
|
bot = Discordrb::Commands::CommandBot.new token: $settings['token'], prefix: $settings['prefix']
|
|
@@ -217,5 +220,54 @@ bot.command(:volume, description: "Sets the severity of currently playing 'music
|
|
|
""
|
|
|
end
|
|
|
|
|
|
+bot.command(:give, description: "Give a user some Good Boy Points (GBP).") do |_event|
|
|
|
+ receiver = _event.message.mentions[0]
|
|
|
+ sender = _event.author
|
|
|
+ next 'You cannot give GBP to yourself.' if sender.id == receiver.id
|
|
|
+ result = db.query "SELECT remaining FROM gbp WHERE user_id=?", sender.id
|
|
|
+ first_result = result.next
|
|
|
+ if first_result
|
|
|
+ remaining = first_result[0]
|
|
|
+ else
|
|
|
+ remaining = $settings['gbp_per_week']
|
|
|
+ db.execute "INSERT INTO gbp VALUES (?, ?, ?)", sender.id, 0, $settings['gbp_per_week']
|
|
|
+ end
|
|
|
+ next 'No GBP left to give this week.' unless remaining > 0
|
|
|
+ result = db.query "SELECT received FROM gbp WHERE user_id=?", receiver.id
|
|
|
+ first_result = result.next
|
|
|
+ if first_result
|
|
|
+ received = first_result[0]
|
|
|
+ else
|
|
|
+ received = 0
|
|
|
+ db.execute "INSERT INTO gbp VALUES (?, ?, ?)", receiver.id, 0, $settings['gbp_per_week']
|
|
|
+ end
|
|
|
+ db.execute "UPDATE gbp SET received = ? WHERE user_id = ?", received + 1, receiver.id
|
|
|
+ db.execute "UPDATE gbp SET remaining = ? WHERE user_id = ?", remaining - 1, sender.id
|
|
|
+ "#{sender.mention} gave 1 GBP to #{receiver.mention}."
|
|
|
+end
|
|
|
+
|
|
|
+bot.command(:leaderboard, description: "Show who's got the most Good Boy Points (GBP).") do |_event|
|
|
|
+ results = db.query "SELECT user_id, received FROM gbp ORDER BY received DESC"
|
|
|
+ results.each_with_index.map{|row, i| "#{i + 1}. #{bot.users[row[0]].username} - #{row[1]}"}.join("\n")
|
|
|
+end
|
|
|
+
|
|
|
+bot.voice_state_update() do |_event|
|
|
|
+ user = _event.user
|
|
|
+ channel = _event.channel
|
|
|
+ if channel.id == $settings['naughty_corner']
|
|
|
+ # Deduct GBP
|
|
|
+ result = db.query "SELECT received FROM gbp WHERE user_id=?", user.id
|
|
|
+ first_result = result.next
|
|
|
+ if first_result
|
|
|
+ received = first_result[0]
|
|
|
+ else
|
|
|
+ received = 0
|
|
|
+ db.execute "INSERT INTO gbp VALUES (?, ?, ?)", receiver.id, 0, $settings['gbp_per_week']
|
|
|
+ end
|
|
|
+ next unless received > 0
|
|
|
+
|
|
|
+ db.execute "UPDATE gbp SET received = ? WHERE user_id = ?", received - 1, user.id
|
|
|
+ end
|
|
|
+end
|
|
|
|
|
|
bot.run
|