-
Notifications
You must be signed in to change notification settings - Fork 5
/
twitch_commands.rb
55 lines (42 loc) · 1.02 KB
/
twitch_commands.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
require("open-uri")
require_relative("configurator.rb")
def twitch_command(user, command)
puts("#{"[COMMAND]".bold.cyan} #{user.bold}: #{command.bold.cyan}")
command.gsub!($prefix, "")
response =
case command.split(" ").first
# Regular example
when "ping"
ping(user)
# File example
when "from_file"
from_file("example.txt")
# API example (https://docs.decapi.me/twitch)
when "uptime"
uptime().string # Convert StringIO to String
# Default
else
nil
end
# Send chat message if there is a response
if response != nil
$messages.push(response)
puts("#{" " * (10 + user.length + 1)} #{"\\------".bold.blue}: #{response.yellow}")
end
end
# File Commands
def from_file(file_name)
return open("./responses/#{file_name}").read
end
# Regular Commands
def ping(user)
return "pong #{user}!"
end
# API Commands
def uptime(def_msg: "")
if def_msg != ""
return open("https://decapi.me/twitch/uptime/#{$channel}?offline_msg=#{def_msg}")
else
return open("https://decapi.me/twitch/uptime/#{$channel}")
end
end