twitch addon
This commit is contained in:
parent
2cd7af98a1
commit
07de7179c9
254 changed files with 18420 additions and 1 deletions
32
test/GUT_Settings
Normal file
32
test/GUT_Settings
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"background_color": "262626ff",
|
||||
"compact_mode": false,
|
||||
"configured_dirs": [
|
||||
"res://test/"
|
||||
],
|
||||
"dirs": [
|
||||
"res://test/"
|
||||
],
|
||||
"disable_colors": false,
|
||||
"double_strategy": 1,
|
||||
"errors_do_not_cause_failure": false,
|
||||
"font_color": "ccccccff",
|
||||
"font_name": "CourierPrime",
|
||||
"font_size": 16,
|
||||
"gut_on_top": true,
|
||||
"hide_orphans": false,
|
||||
"ignore_pause": false,
|
||||
"include_subdirs": true,
|
||||
"junit_xml_file": "",
|
||||
"junit_xml_timestamp": false,
|
||||
"log_level": 1,
|
||||
"opacity": 100,
|
||||
"paint_after": 0.1,
|
||||
"post_run_script": "",
|
||||
"pre_run_script": "",
|
||||
"prefix": "test_",
|
||||
"should_exit": false,
|
||||
"should_exit_on_success": false,
|
||||
"should_maximize": false,
|
||||
"suffix": ".gd"
|
||||
}
|
||||
35
test/test_VST_auth_server.gd
Normal file
35
test/test_VST_auth_server.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
extends GutTest
|
||||
|
||||
var server:VSTAuthServer
|
||||
|
||||
func before_all():
|
||||
server = load("res://addons/very-simple-twitch/auth_server.gd").new()
|
||||
|
||||
func after_all():
|
||||
server.queue_free()
|
||||
|
||||
func test_handle_post():
|
||||
var mock_client:StreamPeer = double(StreamPeerBuffer).new()
|
||||
#test nothing happens
|
||||
server.handlePost(mock_client, "http://localhost:8080")
|
||||
watch_signals(server)
|
||||
assert_signal_not_emitted(server, "OnTokenReceived")
|
||||
#test nothing happens
|
||||
server.handlePost(mock_client, "http://localhost:8080?im_not_a_token_param=12345")
|
||||
assert_signal_not_emitted(server, "OnTokenReceived")
|
||||
#test token is spread
|
||||
server.handlePost(mock_client, "http://localhost:8080?token=12345")
|
||||
assert_signal_emitted_with_parameters(server, "OnTokenReceived",["12345"])
|
||||
|
||||
|
||||
func test_handle_get():
|
||||
var mock_client:StreamPeer = double(StreamPeerBuffer).new()
|
||||
server.handleGet(mock_client)
|
||||
var data_to_200:Array = mock_client.get_data(8)
|
||||
assert_ne_deep(data_to_200, [])
|
||||
|
||||
|
||||
func test_load_login_page():
|
||||
var page:String = server.loadLoginPage()
|
||||
assert_ne(page, null)
|
||||
assert_ne(page, "")
|
||||
1
test/test_VST_auth_server.gd.uid
Normal file
1
test/test_VST_auth_server.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dsdgns52vfslm
|
||||
59
test/test_VST_chat.gd
Normal file
59
test/test_VST_chat.gd
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
extends GutTest
|
||||
|
||||
var server:VSTAuthServer
|
||||
|
||||
func test_initial_settings():
|
||||
var client_id:String = VSTSettings.get_setting(VSTSettings.settings.client_id)
|
||||
assert_eq(client_id, "", "For security reasons no client id should be pushed to the public repository.") # no initial value
|
||||
assert_eq(VSTSettings.settings.client_id.path, "config/client_id")
|
||||
|
||||
var twitch_chat_url:String = VSTSettings.get_setting(VSTSettings.settings.twitch_chat_url)
|
||||
assert_eq(twitch_chat_url, "wss://irc-ws.chat.twitch.tv")
|
||||
assert_eq(VSTSettings.settings.twitch_chat_url.path, "advanced_config/twitch_chat_url")
|
||||
|
||||
var twitch_chat_port:int = VSTSettings.get_setting(VSTSettings.settings.twitch_port)
|
||||
assert_eq(twitch_chat_port, 443)
|
||||
assert_eq(VSTSettings.settings.twitch_port.path, "advanced_config/twitch_port")
|
||||
|
||||
var use_cache:bool = VSTSettings.get_setting(VSTSettings.settings.disk_cache)
|
||||
assert_eq(use_cache, true)
|
||||
assert_eq(VSTSettings.settings.disk_cache.path, "config/disk_cache")
|
||||
|
||||
var cache_path:String = VSTSettings.get_setting(VSTSettings.settings.disk_cache_path)
|
||||
assert_eq(cache_path, "user://very-simple-chat/cache")
|
||||
assert_eq(VSTSettings.settings.disk_cache_path.path, "advanced_config/disk_cache_path")
|
||||
|
||||
var chat_timeout_ms:int = VSTSettings.get_setting(VSTSettings.settings.twitch_timeout_ms)
|
||||
assert_eq(chat_timeout_ms, 320)
|
||||
assert_eq(VSTSettings.settings.twitch_timeout_ms.path, "advanced_config/twitch_timeout_ms")
|
||||
|
||||
var scopes:Array = VSTSettings.get_setting(VSTSettings.settings.scopes)
|
||||
assert_eq_deep(scopes, ["moderator:manage:banned_users","chat:read", "channel:manage:vips"])
|
||||
assert_eq(VSTSettings.settings.scopes.path, "config/scopes")
|
||||
|
||||
var twitch_anon_user:String = VSTSettings.get_setting(VSTSettings.settings.twitch_anon_user)
|
||||
assert_eq(twitch_anon_user, "justinfan5555")
|
||||
assert_eq(VSTSettings.settings.twitch_anon_user.path, "advanced_config/twitch_anon_user")
|
||||
|
||||
var twitch_anon_pass:String = VSTSettings.get_setting(VSTSettings.settings.twitch_anon_pass)
|
||||
assert_eq(twitch_anon_pass, "kappa")
|
||||
assert_eq(VSTSettings.settings.twitch_anon_pass.path, "advanced_config/twitch_anon_pass")
|
||||
|
||||
func test_parse_message_to_chatter():
|
||||
var twitch_chat:VSTChat = load("res://addons/very-simple-twitch/twitch_chat.gd").new()
|
||||
var parsed_message:PackedStringArray = twitch_chat.parse_message_from_twtich_IRC("@badge-info=;badges=broadcaster/1;client-nonce=28e05b1c83f1e916ca1710c44b014515;color=#0000FF;display-name=godot_oficial;emotes=62835:0-10;first-msg=0;flags=;id=f80a19d6-e35a-4273-82d0-cd87f614e767;mod=0;room-id=713936733;subscriber=0;tmi-sent-ts=1642696567751;turbo=0;user-id=713936733;user-type= :godot_oficial!godot_oficial@godot_oficial.tmi.twitch.tv PRIVMSG #xyz :HeyGuys")
|
||||
var chatter:VSTChatter = twitch_chat.parse_message_to_chatter(parsed_message)
|
||||
assert_eq(chatter.channel, "xyz")
|
||||
assert_eq(chatter.login, "godot_oficial")
|
||||
assert_eq(chatter.message, "HeyGuys")
|
||||
assert_eq(chatter.is_mod(), false)
|
||||
assert_eq(chatter.is_sub(), false)
|
||||
assert_eq(chatter.is_broadcaster(), true)
|
||||
|
||||
func test_handle_private_message():
|
||||
var twitch_chat:VSTChat = load("res://addons/very-simple-twitch/twitch_chat.gd").new()
|
||||
watch_signals(twitch_chat)
|
||||
var parsed_message:PackedStringArray = twitch_chat.parse_message_from_twtich_IRC("@badge-info=;badges=broadcaster/1;client-nonce=28e05b1c83f1e916ca1710c44b014515;color=#0000FF;display-name=godot_oficial;emotes=62835:0-10;first-msg=0;flags=;id=f80a19d6-e35a-4273-82d0-cd87f614e767;mod=0;room-id=713936733;subscriber=0;tmi-sent-ts=1642696567751;turbo=0;user-id=713936733;user-type= :godot_oficial!godot_oficial@godot_oficial.tmi.twitch.tv PRIVMSG #xyz :HeyGuys")
|
||||
twitch_chat.handle_privmsg(parsed_message)
|
||||
var chatter:VSTChatter = twitch_chat.parse_message_to_chatter(parsed_message)
|
||||
assert_signal_emitted(twitch_chat, "OnMessage", [chatter])
|
||||
1
test/test_VST_chat.gd.uid
Normal file
1
test/test_VST_chat.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://co4jn7cc1akhd
|
||||
107
test/test_VST_parse_helper.gd
Normal file
107
test/test_VST_parse_helper.gd
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
extends GutTest
|
||||
|
||||
func test_parse_login():
|
||||
# Parse a good substring from a real payload
|
||||
var result:String = VSTParseHelper.parse_login(":rothio!rothio@rothio.tmi.twitch.tv")
|
||||
assert_eq(result, "rothio")
|
||||
result = VSTParseHelper.parse_login(":rothiotome!rothiotome@rothiotome.tmi.twitch.tv")
|
||||
assert_eq(result, "rothiotome")
|
||||
|
||||
# Not parsing a wrong substring
|
||||
result = VSTParseHelper.parse_login("bad_login_rothiotome")
|
||||
assert_eq(result, "bad_login_rothiotome")
|
||||
|
||||
|
||||
func test_parse_channel():
|
||||
# Parse a good substring from a real payload
|
||||
var result:String = VSTParseHelper.parse_channel("#rothio")
|
||||
assert_eq(result, "rothio")
|
||||
|
||||
# Not parsing a wrong substring from payload
|
||||
result = VSTParseHelper.parse_channel("_rothio_bad_channel")
|
||||
assert_eq(result, "_rothio_bad_channel")
|
||||
|
||||
|
||||
func test_parse_message():
|
||||
# Parse a good substring from a real payload
|
||||
var result:String = VSTParseHelper.parse_message(":rothioCuchillo rothioJeje")
|
||||
assert_eq(result, "rothioCuchillo rothioJeje")
|
||||
result = VSTParseHelper.parse_message(": rothioCuchillo rothioJeje ")
|
||||
assert_eq(result, "rothioCuchillo rothioJeje")
|
||||
|
||||
# Not parsing a wrong substring from payload
|
||||
result = VSTParseHelper.parse_message("_rothioCuchillo rothioJeje")
|
||||
assert_eq(result, "_rothioCuchillo rothioJeje")
|
||||
|
||||
|
||||
func test_parse_tags():
|
||||
var result:VSTIRCTags = VSTParseHelper.parse_tags("@badge-info=subscriber/21;badges=broadcaster/1,subscriber/0;client-nonce=1f0134354;color=#FF666F;display-name=RothioTome;emote-only=1;emotes=emotesv2_3328e0d6b6714a6a90dc8f58d09e5648:11-24/emotesv2_4b9a9537c7e34c3395ada46471c4097e:26-35;first-msg=0;flags=;id=6da896da-f543-4928-b5b0-ad84f216a0e3;mod=0;returning-chatter=0;room-id=156108906;subscriber=1;tmi-sent-ts=1;turbo=0;user-id=1;user-type=")
|
||||
assert_eq(result.user_id, "156108906")
|
||||
|
||||
assert_eq(result.color_hex, "#FF666F")
|
||||
assert_eq(result.display_name, "RothioTome")
|
||||
|
||||
var parsed_badges:Dictionary = {"broadcaster": "1", "subscriber": "0"}
|
||||
assert_eq_deep(result.badges, parsed_badges)
|
||||
|
||||
var parsed_emotes:Dictionary = { "emotesv2_3328e0d6b6714a6a90dc8f58d09e5648": "11-24",
|
||||
"emotesv2_4b9a9537c7e34c3395ada46471c4097e": "26-35" }
|
||||
|
||||
assert_eq_deep(result.emotes, parsed_emotes)
|
||||
|
||||
|
||||
func test_parse_badges():
|
||||
var array:PackedStringArray = ["verified/2", "broadcaster/1", "subscriber/0"]
|
||||
var parsed:Dictionary = {"verified": "2", "broadcaster": "1", "subscriber": "0"}
|
||||
|
||||
# Parse an array with a good badge format
|
||||
var result:Dictionary = VSTParseHelper.parse_badges(array)
|
||||
assert_eq_deep(result, parsed)
|
||||
|
||||
# Parse an array with some bad badge format
|
||||
array = ["a", "verified/2", "b", "broadcaster/1", "subscriber/0"]
|
||||
result = VSTParseHelper.parse_badges(array)
|
||||
assert_eq_deep(result, parsed)
|
||||
|
||||
# Parse an empty array of badges
|
||||
result = VSTParseHelper.parse_badges([])
|
||||
assert_eq_deep(result, {})
|
||||
|
||||
|
||||
func test_parse_emotes():
|
||||
var array:PackedStringArray = ["emotesv2_3328e0d6b6714a6a90dc8f58d09e5648:11-24",
|
||||
"emotesv2_4b9a9537c7e34c3395ada46471c4097e:26-35"]
|
||||
var parsed:Dictionary = { "emotesv2_3328e0d6b6714a6a90dc8f58d09e5648": "11-24",
|
||||
"emotesv2_4b9a9537c7e34c3395ada46471c4097e": "26-35" }
|
||||
|
||||
# Parse an array with a good emote format
|
||||
var result:Dictionary = VSTParseHelper.parse_emotes(array)
|
||||
assert_eq_deep(result, parsed)
|
||||
|
||||
# Parse an empty emote array
|
||||
result = VSTParseHelper.parse_emotes([])
|
||||
assert_eq_deep(result,{})
|
||||
|
||||
# Parse an array with a wrong emote format
|
||||
array = ["emotesv2_3328e0d6b6714a6a90dc8f58d09e5648:11-24",
|
||||
"emotesv2_4b9a9537c7e34c3395ada46471c4097e:26-35", "a", "b"]
|
||||
result = VSTParseHelper.parse_emotes(array)
|
||||
assert_eq_deep(result, parsed)
|
||||
|
||||
|
||||
func test_parse_substring():
|
||||
# Returning expected value from char to char substring
|
||||
var result:String = VSTParseHelper.get_substring(":abc!",":","!")
|
||||
assert_eq(result, "abc")
|
||||
result = VSTParseHelper.get_substring("abcdef","b","f")
|
||||
assert_eq(result, "cde")
|
||||
result = VSTParseHelper.get_substring(":abc!","!","!")
|
||||
assert_eq(result, "")
|
||||
|
||||
# Returning the same value from a invalid or not found chars
|
||||
result = VSTParseHelper.get_substring(":abc!","x","!")
|
||||
assert_eq(result, ":abc!")
|
||||
result = VSTParseHelper.get_substring(":abc!","!","x")
|
||||
assert_eq(result, ":abc!")
|
||||
result = VSTParseHelper.get_substring(":abc!","c","a")
|
||||
assert_eq(result, ":abc!")
|
||||
1
test/test_VST_parse_helper.gd.uid
Normal file
1
test/test_VST_parse_helper.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://723ho4ae3ekv
|
||||
36
test/test_VST_utils.gd
Normal file
36
test/test_VST_utils.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
extends GutTest
|
||||
|
||||
|
||||
func test_get_random_name_color():
|
||||
var color_rothio_a:Color = VSTUtils.get_random_name_color("Rothio", 0)
|
||||
var color_rothio_b:Color = VSTUtils.get_random_name_color("Rothio", 0)
|
||||
assert_not_null(color_rothio_a)
|
||||
assert_not_null(color_rothio_b)
|
||||
assert_eq(color_rothio_a, color_rothio_b)
|
||||
var color_rothio_c:Color = VSTUtils.get_random_name_color("Rothio", 1)
|
||||
assert_not_same(color_rothio_a, color_rothio_c)
|
||||
assert_not_same(color_rothio_b, color_rothio_c)
|
||||
|
||||
|
||||
func test_normalize_color():
|
||||
var color_dark:Color = Color.BLACK
|
||||
var color_dark_normalized:Color = VSTUtils.normalize_color(color_dark)
|
||||
var color_light:Color = Color.WHITE
|
||||
var color_light_normalized:Color = VSTUtils.normalize_color(color_light)
|
||||
var color_normal:Color = Color.LIGHT_CORAL
|
||||
var color_normal_normalized:Color = VSTUtils.normalize_color(color_normal)
|
||||
assert_eq(color_normal_normalized, Color.LIGHT_CORAL)
|
||||
assert_eq(color_light_normalized, Color(0.8, 0.8, 0.8, 1))
|
||||
assert_eq(color_dark_normalized, Color(0.2, 0.2, 0.2, 1))
|
||||
|
||||
|
||||
func test_normalize_color_str():
|
||||
var color_dark:Color = Color.BLACK
|
||||
var color_dark_normalized:Color = VSTUtils.normalize_hex_color(color_dark.to_html())
|
||||
var color_light:Color = Color.WHITE
|
||||
var color_light_normalized:Color = VSTUtils.normalize_hex_color(color_light.to_html())
|
||||
var color_normal:Color = Color.LIGHT_CORAL
|
||||
var color_normal_normalized:Color = VSTUtils.normalize_hex_color(color_normal.to_html())
|
||||
assert_eq(color_normal_normalized, Color.LIGHT_CORAL)
|
||||
assert_eq(color_light_normalized, Color(0.8, 0.8, 0.8, 1))
|
||||
assert_eq(color_dark_normalized, Color(0.2, 0.2, 0.2, 1))
|
||||
1
test/test_VST_utils.gd.uid
Normal file
1
test/test_VST_utils.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b70xel4bkuti7
|
||||
Loading…
Add table
Add a link
Reference in a new issue