|
@@ -4,6 +4,7 @@ require 'yaml'
|
|
|
require 'json'
|
|
require 'json'
|
|
|
require 'terminal-table'
|
|
require 'terminal-table'
|
|
|
require 'rmagick'
|
|
require 'rmagick'
|
|
|
|
|
+require 'down'
|
|
|
|
|
|
|
|
BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
|
|
BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
|
|
|
Bundler.require(:default, BOT_ENV)
|
|
Bundler.require(:default, BOT_ENV)
|
|
@@ -42,6 +43,107 @@ Dir['./lib/*.rb'].each { |f| require f }
|
|
|
token = ENV['DISCORD_BOT_TOKEN']
|
|
token = ENV['DISCORD_BOT_TOKEN']
|
|
|
bot = Discordrb::Bot.new(token: token)
|
|
bot = Discordrb::Bot.new(token: token)
|
|
|
|
|
|
|
|
|
|
+# Methods
|
|
|
|
|
+
|
|
|
|
|
+def stat_image(user, member, stats=nil)
|
|
|
|
|
+ size_width = 570;
|
|
|
|
|
+ size_height = 376;
|
|
|
|
|
+ stats_frame = "images/LevelUp.png"
|
|
|
|
|
+ level_up = "images/LevelUpFont.png"
|
|
|
|
|
+ user_url_img = "images/Image_Builder/user_url_img.png"
|
|
|
|
|
+ output_file = "images/Image_Builder/LevelUp"
|
|
|
|
|
+
|
|
|
|
|
+ Down.download(member.avatar_url, destination: user_url_img)
|
|
|
|
|
+
|
|
|
|
|
+ #Gif Destroyer
|
|
|
|
|
+ i = Magick::ImageList.new(user_url_img)
|
|
|
|
|
+ i[0].write(user_url_img) if i.count > 1
|
|
|
|
|
+
|
|
|
|
|
+ if stats
|
|
|
|
|
+ merge_image(
|
|
|
|
|
+ [stats_frame, level_up, user_url_img],
|
|
|
|
|
+ output_file,
|
|
|
|
|
+ size_width,
|
|
|
|
|
+ size_height,
|
|
|
|
|
+ [nil, nil, 19],
|
|
|
|
|
+ [nil, nil, 92],
|
|
|
|
|
+ [size_width, size_width, 165],
|
|
|
|
|
+ [size_height, size_height, 165]
|
|
|
|
|
+ )
|
|
|
|
|
+ else
|
|
|
|
|
+ merge_image(
|
|
|
|
|
+ [stats_frame, user_url_img],
|
|
|
|
|
+ output_file,
|
|
|
|
|
+ size_width,
|
|
|
|
|
+ size_height,
|
|
|
|
|
+ [nil, 19],
|
|
|
|
|
+ [nil, 92],
|
|
|
|
|
+ [size_width, 165],
|
|
|
|
|
+ [size_height, 165]
|
|
|
|
|
+ )
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ ratio = 0.5
|
|
|
|
|
+ user_name = member.nickname || member.name
|
|
|
|
|
+ short_name = user_name.length > 25 ? "#{user_name[0..22]}..." : user_name
|
|
|
|
|
+ rank = User.order(unboosted_xp: :desc)
|
|
|
|
|
+ user_rank = rank.index{ |r| r.id == user.id } + 1
|
|
|
|
|
+
|
|
|
|
|
+ gc = Draw.new
|
|
|
|
|
+
|
|
|
|
|
+ gc.font('OpenSans-SemiBold.ttf')
|
|
|
|
|
+
|
|
|
|
|
+ gc.stroke('#39c4ff').fill('#39c4ff')
|
|
|
|
|
+ gc.rectangle(42, 48, 42 + (95 * ratio), 48 + 3)
|
|
|
|
|
+
|
|
|
|
|
+ gc.stroke('none').fill('black')
|
|
|
|
|
+ gc.pointsize('15')
|
|
|
|
|
+ gc.text(15,25, short_name)
|
|
|
|
|
+ gc.text(40, 45, "Lv.#{user.level}")
|
|
|
|
|
+ gc.text(15, 290, "Rank: #{user_rank}")
|
|
|
|
|
+ gc.text(40, 65, "Exp: #{user.boosted_xp}")
|
|
|
|
|
+
|
|
|
|
|
+ gc.stroke('white').fill('white')
|
|
|
|
|
+ gc.pointsize('30')
|
|
|
|
|
+ gc.text(40,330, user_name)
|
|
|
|
|
+ gc.text(40,360, "reached level #{user.level}!")
|
|
|
|
|
+
|
|
|
|
|
+ if stats
|
|
|
|
|
+ gc.stroke('none').fill('black')
|
|
|
|
|
+ gc.pointsize('18')
|
|
|
|
|
+ gc.text(450, 97, stats['hp'].to_s)
|
|
|
|
|
+ gc.text(450, 127, stats['attack'].to_s)
|
|
|
|
|
+ gc.text(450, 159, stats['defense'].to_s)
|
|
|
|
|
+ gc.text(450, 191, stats['sp_attack'].to_s)
|
|
|
|
|
+ gc.text(450, 222, stats['sp_defense'].to_s)
|
|
|
|
|
+ gc.text(450, 255, stats['speed'].to_s)
|
|
|
|
|
+
|
|
|
|
|
+ gc.stroke('none').fill('maroon')
|
|
|
|
|
+ gc.text(505, 97, "+ #{stats['hp'] - user.hp}")
|
|
|
|
|
+ gc.text(505, 127, "+ #{stats['attack']- user.attack}")
|
|
|
|
|
+ gc.text(505, 159, "+ #{stats['defense'] - user.defense}")
|
|
|
|
|
+ gc.text(505, 191, "+ #{stats['sp_attack'] - user.sp_attack}")
|
|
|
|
|
+ gc.text(505, 222, "+ #{stats['sp_defense']- user.sp_defense}")
|
|
|
|
|
+ gc.text(505, 255, "+ #{stats['speed'] - user.speed}")
|
|
|
|
|
+ else
|
|
|
|
|
+ gc.stroke('none').fill('black')
|
|
|
|
|
+ gc.pointsize('18')
|
|
|
|
|
+ gc.text(450, 97, user.hp.to_s)
|
|
|
|
|
+ gc.text(450, 127, user.attack.to_s)
|
|
|
|
|
+ gc.text(450, 159, user.defense.to_s)
|
|
|
|
|
+ gc.text(450, 191, user.sp_attack.to_s)
|
|
|
|
|
+ gc.text(450, 222, user.sp_defense.to_s)
|
|
|
|
|
+ gc.text(450, 255, user.speed.to_s)
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ u = Magick::ImageList.new("#{output_file}.png")
|
|
|
|
|
+ gc.draw(u[0])
|
|
|
|
|
+
|
|
|
|
|
+ u.write("#{output_file}.png")
|
|
|
|
|
+ "#{output_file}.png"
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+#--
|
|
|
|
|
|
|
|
# Commands: structure basic bot commands here
|
|
# Commands: structure basic bot commands here
|
|
|
commands = []
|
|
commands = []
|
|
@@ -124,6 +226,34 @@ matchup = Command.new(:matchup, desc, opts) do |event, primary, secondary|
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+opts = {
|
|
|
|
|
+ "@user" => "List all user stats",
|
|
|
|
|
+}
|
|
|
|
|
+desc = "Shows ones stats, level, rank, and experience"
|
|
|
|
|
+stats = Command.new(:stats, desc, opts) do |event, name|
|
|
|
|
|
+
|
|
|
|
|
+ case name
|
|
|
|
|
+ when UID
|
|
|
|
|
+ user_id = UID.match(name)
|
|
|
|
|
+ user = event.server.member(user_id[1])
|
|
|
|
|
+ when String
|
|
|
|
|
+ #See if you can find the name some other way?
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ channel = event.channel.id
|
|
|
|
|
+
|
|
|
|
|
+ # C# code for getting the percantage to the next level
|
|
|
|
|
+ #int levelprior = LevelUp[task].NextLevel - (10 * (LevelUp[task].CurrentLevel - 1) ^ 2);
|
|
|
|
|
+ #double ratio = (double)(LevelUp[task].Messages - levelprior) / (double)(LevelUp[task].NextLevel - levelprior);
|
|
|
|
|
+
|
|
|
|
|
+ usr = User.find_by!(id: user&.id)
|
|
|
|
|
+
|
|
|
|
|
+ output_file = stat_image(usr, user)
|
|
|
|
|
+ bot.send_file(channel, File.open(output_file, 'r'))
|
|
|
|
|
+rescue ActiveRecord::RecordNotFound => e
|
|
|
|
|
+ error_embed(e.message)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
opts = {
|
|
opts = {
|
|
|
"" => "starts a new app",
|
|
"" => "starts a new app",
|
|
|
"name" => "edits an existing app",
|
|
"name" => "edits an existing app",
|
|
@@ -423,11 +553,12 @@ member = Command.new(:member, desc, opts) do |event, name, section, keyword|
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-
|
|
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
|
error_embed("Record Not Found!", e.message)
|
|
error_embed("Record Not Found!", e.message)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+desc = "Learn about Items"
|
|
|
|
|
+opts = { "" => "list all items", "item_name" => "show known info for the item" }
|
|
|
item = Command.new(:item, desc, opts) do |event, name|
|
|
item = Command.new(:item, desc, opts) do |event, name|
|
|
|
i = name ? Item.find_by!(name: name.capitalize) : Item.all
|
|
i = name ? Item.find_by!(name: name.capitalize) : Item.all
|
|
|
|
|
|
|
@@ -444,7 +575,7 @@ rescue ActiveRecord::RecordNotFound
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
desc = "Add and remove items from characters' inventories"
|
|
desc = "Add and remove items from characters' inventories"
|
|
|
-opts = { "item | (-/+) amount | character" => "" }
|
|
|
|
|
|
|
+opts = { "item | (-/+) amount | character" => "negative numbers remove items" }
|
|
|
inv = Command.new(:inv, desc, opts) do |event, item, amount, name|
|
|
inv = Command.new(:inv, desc, opts) do |event, item, amount, name|
|
|
|
char = Character.find_by!(name: name) if name
|
|
char = Character.find_by!(name: name) if name
|
|
|
itm = Item.find_by!(name: item) if item
|
|
itm = Item.find_by!(name: item) if item
|
|
@@ -472,23 +603,33 @@ rescue ActiveRecord::RecordNotFound => e
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
desc = "Update or edit statuses"
|
|
desc = "Update or edit statuses"
|
|
|
-opts = { "name | effect" => "" }
|
|
|
|
|
-status = Command.new(:status, desc, opts) do |event, name, effect|
|
|
|
|
|
- if name && effect
|
|
|
|
|
- s = StatusController.edit_status(name, effect)
|
|
|
|
|
|
|
+opts = { "name | effect" => "effect displays on user when afflicted" }
|
|
|
|
|
+status = Command.new(:status, desc, opts) do |event, name, effect, flag|
|
|
|
|
|
+ admin = event.user.roles.map(&:name).include?('Guild Masters')
|
|
|
|
|
+
|
|
|
|
|
+ if name && effect && admin
|
|
|
|
|
+ s = StatusController.edit_status(name, effect, flag)
|
|
|
|
|
|
|
|
case s
|
|
case s
|
|
|
when Status
|
|
when Status
|
|
|
- success_embed("Created Status: #{name}")
|
|
|
|
|
|
|
+ status_details(s)
|
|
|
when Embed
|
|
when Embed
|
|
|
s
|
|
s
|
|
|
end
|
|
end
|
|
|
|
|
+ elsif name && !effect
|
|
|
|
|
+ status_details(Status.find_by!(name: name))
|
|
|
|
|
+ elsif !name && !effect
|
|
|
|
|
+ status_list
|
|
|
|
|
+ elsif !admin
|
|
|
|
|
+ error_embed("You do not have permission to do that!")
|
|
|
else
|
|
else
|
|
|
command_error_embed("Could not create status!", status)
|
|
command_error_embed("Could not create status!", status)
|
|
|
end
|
|
end
|
|
|
|
|
+rescue ActiveRecord::RecordNotFound => e
|
|
|
|
|
+ error_embed(e.message)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-opts = { "character | ailment | %afflicted" => "" }
|
|
|
|
|
|
|
+opts = { "character | ailment | %afflicted" => "afflictions apply in percentages" }
|
|
|
afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
|
|
afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
|
|
|
char = Character.find_by!(name: name) if name
|
|
char = Character.find_by!(name: name) if name
|
|
|
st = Status.find_by!(name: status) if status
|
|
st = Status.find_by!(name: status) if status
|
|
@@ -496,12 +637,12 @@ afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
|
|
|
user = char.user_id.match(/public/i) ?
|
|
user = char.user_id.match(/public/i) ?
|
|
|
'Public' : event.server.member(char.user_id)
|
|
'Public' : event.server.member(char.user_id)
|
|
|
|
|
|
|
|
- if st && amount && char
|
|
|
|
|
|
|
+ if st && char
|
|
|
user = char.user_id.match(/public/i) ?
|
|
user = char.user_id.match(/public/i) ?
|
|
|
'Public' : event.server.member(char.user_id)
|
|
'Public' : event.server.member(char.user_id)
|
|
|
color = CharacterController.type_color(char)
|
|
color = CharacterController.type_color(char)
|
|
|
|
|
|
|
|
- s = StatusController.edit_char_status(st, amount, char)
|
|
|
|
|
|
|
+ s = StatusController.edit_char_status(char, st, amount)
|
|
|
|
|
|
|
|
case s
|
|
case s
|
|
|
when CharStatus
|
|
when CharStatus
|
|
@@ -510,7 +651,7 @@ afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
|
|
|
s
|
|
s
|
|
|
end
|
|
end
|
|
|
else
|
|
else
|
|
|
- command_error_embed("Error afflicting #{char}", afflict)
|
|
|
|
|
|
|
+ command_error_embed("Error afflicting #{char.name}", afflict)
|
|
|
end
|
|
end
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
|
error_embed(e.message)
|
|
error_embed(e.message)
|
|
@@ -635,12 +776,13 @@ commands = [
|
|
|
poll,
|
|
poll,
|
|
|
raffle,
|
|
raffle,
|
|
|
member,
|
|
member,
|
|
|
- item,
|
|
|
|
|
- inv,
|
|
|
|
|
|
|
+ #item,
|
|
|
|
|
+ #inv,
|
|
|
status,
|
|
status,
|
|
|
afflict,
|
|
afflict,
|
|
|
cure,
|
|
cure,
|
|
|
- team
|
|
|
|
|
|
|
+ team,
|
|
|
|
|
+ stats
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
#locked_commands = [inv]
|
|
#locked_commands = [inv]
|
|
@@ -674,27 +816,14 @@ bot.message do |event|
|
|
|
else
|
|
else
|
|
|
approval_react(event)
|
|
approval_react(event)
|
|
|
end
|
|
end
|
|
|
- #elsif content == 'test'
|
|
|
|
|
- #User.import_user(File.open('users.txt', 'r'))
|
|
|
|
|
- elsif content == 'pry'
|
|
|
|
|
- binding.pry
|
|
|
|
|
- elsif content == 'show me dem illegals'
|
|
|
|
|
- users = User.all
|
|
|
|
|
- illegals = []
|
|
|
|
|
-
|
|
|
|
|
- users.each do |u|
|
|
|
|
|
- allowed = u.level / 10 + 1
|
|
|
|
|
- active = Character.where(user_id: u.id, active: 'Active').count
|
|
|
|
|
- illegals.push("<@#{u.id}>, Level #{u.level}: #{active}/#{allowed}") if active > allowed
|
|
|
|
|
- end
|
|
|
|
|
- embed = error_embed("Members with too many pokemon", illegals.join("\n"))
|
|
|
|
|
- event.send_embed("", embed)
|
|
|
|
|
|
|
+ elsif content == 'import users' && author == 215240568245190656
|
|
|
|
|
+ User.import_user(File.open('users.txt', 'r'))
|
|
|
elsif !event.author.current_bot?
|
|
elsif !event.author.current_bot?
|
|
|
usr = User.find_by(id: author.to_s)
|
|
usr = User.find_by(id: author.to_s)
|
|
|
msg = URL.match(content) ? content.gsub(URL, "x" * 149) : content
|
|
msg = URL.match(content) ? content.gsub(URL, "x" * 149) : content
|
|
|
|
|
|
|
|
- usr = usr.update_xp(msg)
|
|
|
|
|
- event.respond(usr) if usr.is_a? String
|
|
|
|
|
|
|
+ img = usr.update_xp(msg, event.author)
|
|
|
|
|
+ bot.send_file(event.message.channel, File.open(img, 'r')) if img
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -762,8 +891,8 @@ bot.reaction_add do |event|
|
|
|
|
|
|
|
|
vote =
|
|
vote =
|
|
|
case
|
|
case
|
|
|
- when reactions[Emoji::Y]&.count.to_i > maj.round then :yes
|
|
|
|
|
- when reactions[Emoji::N]&.count.to_i > maj.round then :no
|
|
|
|
|
|
|
+ when reactions[Emoji::Y]&.count.to_i > maj then :yes
|
|
|
|
|
+ when reactions[Emoji::N]&.count.to_i > maj then :no
|
|
|
when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
|
|
when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
|
|
|
when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
|
|
when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
|
|
|
when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
|
|
when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
|
|
@@ -788,12 +917,16 @@ bot.reaction_add do |event|
|
|
|
uid = UID.match(app.description)
|
|
uid = UID.match(app.description)
|
|
|
user =
|
|
user =
|
|
|
app.description.match(/public/i) ? 'Public' : event.server.member(uid[1])
|
|
app.description.match(/public/i) ? 'Public' : event.server.member(uid[1])
|
|
|
|
|
+ img_url = case
|
|
|
|
|
+ when !app.thumbnail&.url.nil? then app.thumbnail.url
|
|
|
|
|
+ when !app.image&.url.nil? then app.image.url
|
|
|
|
|
+ end
|
|
|
|
|
|
|
|
char = CharacterController.edit_character(app)
|
|
char = CharacterController.edit_character(app)
|
|
|
img = ImageController.default_image(
|
|
img = ImageController.default_image(
|
|
|
- app.thumbnail.url,
|
|
|
|
|
|
|
+ img_url,
|
|
|
char.id
|
|
char.id
|
|
|
- )if app.thumbnail
|
|
|
|
|
|
|
+ )if img_url
|
|
|
color = CharacterController.type_color(char)
|
|
color = CharacterController.type_color(char)
|
|
|
|
|
|
|
|
embed = character_embed(
|
|
embed = character_embed(
|