-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.rb
32 lines (24 loc) · 860 Bytes
/
bot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'discordrb'
require 'json'
require 'erb'
require 'uri'
require 'active_support/core_ext/hash'
include ERB::Util
bot = Discordrb::Bot.new(token: ENV['DISCORD_API_TOKEN'], client_id: ENV['DISCORD_APP_ID'])
bot.message(start_with: ['[{"id":"', '{"id":"', '[{"name":"']) do |event|
cards = JSON.parse(event.message.content)
cards = [cards] if cards.is_a?(Hash)
cards.each do |card|
card.slice!('name', 'spriteID', 'type', 'cost', 'stats', 'text')
puts card
name, text = card['name'], card['text'].gsub('%27', '"')
# puts text
# puts url_encode(text)
card['name'] = url_encode(card['name'])
card['text'] = url_encode(card['text'])
puts JSON.generate(card)
image_url = "http://app.wordbots.io/api/card.png?card=#{JSON.generate(card)}"
event.respond "**#{name}**\n#{text}\n#{image_url}"
end
end
bot.run