-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitch_emojipacks.rb
64 lines (57 loc) · 1.68 KB
/
twitch_emojipacks.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'httparty'
require 'pry'
require 'yaml'
class TwitchEmojipacks
include HTTParty
def initialize(twitch_channel)
@twitch_channel = twitch_channel
end
def save_twitch_emoticons_to_emojipacks_yaml
twitch_emotes = get_twitch_emoticons
yaml_content = to_emojipacks_yaml(twitch_emotes)
# Store to Emojipacks compatible YAML
File.open("emojipacks/#{@twitch_channel}.yaml", 'w') { |f| f.write yaml_content }
end
##
# Fetches twitch emoticons from channel_name
#
def get_twitch_emoticons
# Get Emoticons for Channel
headers = {
'Accept' => 'application/vnd.twitchtv.v3+json',
'Client-ID' => 'efq3aoz1vvrtac1wz0ojszl54p6uuw'
}
http_response = self.class.get(
"https://api.twitch.tv/kraken/chat/#{@twitch_channel}/emoticons",
headers: headers
)
response = JSON.parse(http_response.body, symbolize_names: true)
emoticons = response[:emoticons]
emoticons = emoticons.select do |e|
e[:state] == 'active' && e[:subscriber_only]
end
emoticons
end
private
##
# Cleans the raw emoticon response from Twitch into a useful hash for Emojipacks
#
def to_emojipacks_yaml(raw_emoticon_response)
result_hash = {
'title' => @twitch_channel,
'emojis' => []
}
raw_emoticon_response.each do |e|
result_hash['emojis'] << { 'name' => e[:regex].downcase, 'src' => e[:url] }
end
result_hash.to_yaml
end
end
if ARGV[0].nil?
puts "Missing Twitch Channel argument"
else
connector = TwitchEmojipacks.new(ARGV[0])
puts "Getting subscriber only emotes for #{ARGV[0]}"
connector.save_twitch_emoticons_to_emojipacks_yaml
puts "Emojipack saved to: emojipacks/#{ARGV[0]}.yaml"
end