-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da2e6aa
commit a7dfdf3
Showing
23 changed files
with
1,013 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
auth.txt | ||
|
||
# Godot-specific ignores | ||
.import/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tool | ||
extends Button | ||
|
||
func _pressed(): | ||
$"../../../Gift".chat($"../LineEdit".text) | ||
$"../LineEdit".text = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
tool | ||
extends VBoxContainer | ||
|
||
func put_chat(senderdata : SenderData, msg : String): | ||
var msgnode : Control = preload("res://addons/TwitchChat/ChatDock/ChatMessage.tscn").instance() | ||
var time = OS.get_time() | ||
var badges : String = "" | ||
if ($"../Gift".image_cache): | ||
for badge in senderdata.tags["badges"].split(",", false): | ||
badges += "[img=center]" + $"../Gift".image_cache.get_badge(badge, senderdata.tags["room-id"]).resource_path + "[/img] " | ||
var locations : Array = [] | ||
for emote in senderdata.tags["emotes"].split("/", false): | ||
var data : Array = emote.split(":") | ||
for d in data[1].split(","): | ||
var start_end = d.split("-") | ||
locations.append(EmoteLocation.new(data[0], int(start_end[0]), int(start_end[1]))) | ||
locations.sort_custom(EmoteLocation, "smaller") | ||
var offset = 0 | ||
for loc in locations: | ||
var emote_string = "[img=center]" + $"../Gift".image_cache.get_emote(loc.id).resource_path +"[/img]" | ||
msg = msg.substr(0, loc.start + offset) + emote_string + msg.substr(loc.end + offset + 1) | ||
offset += emote_string.length() + loc.start - loc.end - 1 | ||
var bottom : bool = $Chat/ScrollContainer.scroll_vertical == $Chat/ScrollContainer.get_v_scrollbar().max_value - $Chat/ScrollContainer.get_v_scrollbar().rect_size.y | ||
msgnode.set_msg(str(time["hour"]) + ":" + ("0" + str(time["minute"]) if time["minute"] < 10 else str(time["minute"])), senderdata, msg, badges) | ||
$Chat/ScrollContainer/ChatMessagesContainer.add_child(msgnode) | ||
yield(get_tree(), "idle_frame") | ||
if (bottom): | ||
$Chat/ScrollContainer.scroll_vertical = $Chat/ScrollContainer.get_v_scrollbar().max_value | ||
|
||
class EmoteLocation extends Reference: | ||
var id : String | ||
var start : int | ||
var end : int | ||
|
||
func _init(emote_id, start_idx, end_idx): | ||
self.id = emote_id | ||
self.start = start_idx | ||
self.end = end_idx | ||
|
||
static func smaller(a : EmoteLocation, b : EmoteLocation): | ||
return a.start < b.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
tool | ||
extends Control | ||
|
||
var base_name:String | ||
|
||
var viewers := 0 | ||
|
||
func _ready(): | ||
base_name = name | ||
|
||
func chat_message(data : SenderData, msg : String) -> void: | ||
$ChatContainer.put_chat(data, msg) | ||
|
||
# Check the CommandInfo class for the available info of the cmd_info. | ||
func command_test(cmd_info : CommandInfo) -> void: | ||
print("A") | ||
|
||
func hello_world(cmd_info : CommandInfo) -> void: | ||
$Gift.chat("HELLO WORLD!") | ||
|
||
func streamer_only(cmd_info : CommandInfo) -> void: | ||
$Gift.chat("Streamer command executed") | ||
|
||
func no_permission(cmd_info : CommandInfo) -> void: | ||
$Gift.chat("NO PERMISSION!") | ||
|
||
func greet(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: | ||
$Gift.chat("Greetings, " + arg_ary[0]) | ||
|
||
func greet_me(cmd_info : CommandInfo) -> void: | ||
$Gift.chat("Greetings, " + cmd_info.sender_data.tags["display-name"] + "!") | ||
|
||
func list(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: | ||
$Gift.chat(arg_ary.join(", ")) | ||
|
||
func _on_Gift_join_message(): | ||
viewers += 1 | ||
|
||
name = base_name + "(" + str(viewers) + ")" | ||
|
||
pass # Replace with function body. | ||
|
||
|
||
func _on_Gift_part_message(): | ||
viewers -= 1 | ||
|
||
name = base_name + "(" + str(viewers) + ")" | ||
|
||
pass # Replace with function body. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
[gd_scene load_steps=6 format=2] | ||
|
||
[ext_resource path="res://addons/TwitchChat/ChatDock/Gift.gd" type="Script" id=1] | ||
[ext_resource path="res://addons/TwitchChat/ChatDock/ChatContainer.gd" type="Script" id=2] | ||
[ext_resource path="res://addons/TwitchChat/ChatDock/Button.gd" type="Script" id=3] | ||
[ext_resource path="res://addons/TwitchChat/ChatDock/ChatDock.gd" type="Script" id=4] | ||
[ext_resource path="res://addons/TwitchChat/icon.png" type="Texture" id=5] | ||
|
||
[node name="TwitchChat" type="Control"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
script = ExtResource( 4 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Gift" type="Node" parent="."] | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_editor_icon": ExtResource( 5 ) | ||
} | ||
get_images = true | ||
|
||
[node name="ChatContainer" type="VBoxContainer" parent="."] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
script = ExtResource( 2 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Chat" type="Panel" parent="ChatContainer"] | ||
show_behind_parent = true | ||
margin_right = 1024.0 | ||
margin_bottom = 572.0 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="ScrollContainer" type="ScrollContainer" parent="ChatContainer/Chat"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = 10.0 | ||
margin_top = 10.0 | ||
margin_right = -10.0 | ||
margin_bottom = -10.0 | ||
follow_focus = true | ||
scroll_horizontal_enabled = false | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="ChatMessagesContainer" type="VBoxContainer" parent="ChatContainer/Chat/ScrollContainer"] | ||
margin_right = 1004.0 | ||
margin_bottom = 552.0 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
custom_constants/separation = 6 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="ChatContainer"] | ||
margin_top = 576.0 | ||
margin_right = 1024.0 | ||
margin_bottom = 600.0 | ||
|
||
[node name="LineEdit" type="LineEdit" parent="ChatContainer/HBoxContainer"] | ||
margin_right = 920.0 | ||
margin_bottom = 24.0 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
caret_blink = true | ||
caret_blink_speed = 0.5 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Button" type="Button" parent="ChatContainer/HBoxContainer"] | ||
margin_left = 924.0 | ||
margin_right = 1024.0 | ||
margin_bottom = 24.0 | ||
rect_min_size = Vector2( 100, 0 ) | ||
text = "Send" | ||
script = ExtResource( 3 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[connection signal="join_message" from="Gift" to="." method="_on_Gift_join_message"] | ||
[connection signal="part_message" from="Gift" to="." method="_on_Gift_part_message"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tool | ||
extends HBoxContainer | ||
|
||
func set_msg(stamp : String, data : SenderData, msg : String, badges : String) -> void: | ||
$RichTextLabel.bbcode_text = stamp + " " + badges + "[b][color="+ data.tags["color"] + "]" + data.tags["display-name"] +"[/color][/b]: " + msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/TwitchChat/ChatDock/ChatMessage.gd" type="Script" id=1] | ||
|
||
[node name="ChatMessage" type="HBoxContainer"] | ||
margin_right = 400.0 | ||
margin_bottom = 24.0 | ||
size_flags_horizontal = 3 | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="RichTextLabel" type="RichTextLabel" parent="."] | ||
margin_right = 400.0 | ||
margin_bottom = 24.0 | ||
focus_mode = 2 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
bbcode_enabled = true | ||
fit_content_height = true | ||
scroll_active = false | ||
selection_enabled = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
tool | ||
extends Gift | ||
|
||
func _ready() -> void: | ||
prints("Gift", "hello") | ||
|
||
# I use a file in the working directory to store auth data | ||
# so that I don't accidentally push it to the repository. | ||
# Replace this or create a auth file with 3 lines in your | ||
# project directory: | ||
# <bot username> | ||
# <oauth token> | ||
# <initial channel> | ||
var authfile := File.new() | ||
authfile.open("./auth.txt", File.READ) | ||
var botname := authfile.get_line() | ||
var token := authfile.get_line() | ||
var initial_channel = authfile.get_line() | ||
|
||
connect_to_twitch() | ||
yield(self, "twitch_connected") | ||
|
||
# Login using your username and an oauth token. | ||
# You will have to either get a oauth token yourself or use | ||
# https://twitchapps.com/tokengen/ | ||
# to generate a token with custom scopes. | ||
authenticate_oauth(botname, token) | ||
if(yield(self, "login_attempt") == false): | ||
print("Invalid username or token.") | ||
return | ||
join_channel(initial_channel) | ||
|
||
var parent := get_parent() | ||
|
||
connect("cmd_no_permission", parent, "no_permission") | ||
connect("chat_message", parent, "chat_message") | ||
connect("whisper_message", parent, "chat_message") | ||
|
||
# Adds a command with a specified permission flag. | ||
# All implementations must take at least one arg for the command info. | ||
# Implementations that recieve args requrires two args, | ||
# the second arg will contain all params in a PoolStringArray | ||
# This command can only be executed by VIPS/MODS/SUBS/STREAMER | ||
add_command("test", parent, "command_test", 0, 0, PermissionFlag.NON_REGULAR) | ||
|
||
# These two commands can be executed by everyone | ||
add_command("helloworld", parent, "hello_world") | ||
add_command("greetme", parent, "greet_me") | ||
|
||
# This command can only be executed by the streamer | ||
add_command("streamer_only", parent, "streamer_only", 0, 0, PermissionFlag.STREAMER) | ||
|
||
# Command that requires exactly 1 arg. | ||
add_command("greet", parent, "greet", 1, 1) | ||
|
||
# Command that prints every arg seperated by a comma (infinite args allowed), at least 2 required | ||
add_command("list", parent, "list", -1, 2) | ||
|
||
# Adds a command alias | ||
add_alias("test","test1") | ||
add_alias("test","test2") | ||
add_alias("test","test3") | ||
# Or do it in a single line | ||
# add_aliases("test", ["test1", "test2", "test3"]) | ||
|
||
# Remove a single command | ||
remove_command("test2") | ||
|
||
# Now only knows commands "test", "test1" and "test3" | ||
remove_command("test") | ||
# Now only knows commands "test1" and "test3" | ||
|
||
# Remove all commands that call the same function as the specified command | ||
purge_command("test1") | ||
# Now no "test" command is known | ||
|
||
# Send a chat message to the only connected channel (<channel_name>) | ||
# Fails, if connected to more than one channel. | ||
# chat("TEST") | ||
|
||
# Send a chat message to channel <channel_name> | ||
# chat("TEST", initial_channel) | ||
|
||
# Send a whisper to target user | ||
# whisper("TEST", initial_channel) |
Oops, something went wrong.