diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 deleted file mode 100644 index f75f542..0000000 --- a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 +++ /dev/null @@ -1,3 +0,0 @@ -source_md5="8dd9ff1eebf38898a54579d8c01b0a88" -dest_md5="da70afec3c66d4e872db67f808e12edb" - diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex deleted file mode 100644 index 46e6d2a..0000000 Binary files a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex and /dev/null differ diff --git a/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.md5 b/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.md5 deleted file mode 100644 index 221c624..0000000 --- a/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.md5 +++ /dev/null @@ -1,3 +0,0 @@ -source_md5="a968f7207fa0b577199e591bee3d650b" -dest_md5="d352d63ef80c05346da08dcf324711fd" - diff --git a/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.stex b/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.stex deleted file mode 100644 index a5bf3f8..0000000 Binary files a/.import/icon.png-b5cf707f4ba91fefa5df60a746e02900.stex and /dev/null differ diff --git a/ChatContainer.gd b/ChatContainer.gd index 0f986d2..d98a390 100644 --- a/ChatContainer.gd +++ b/ChatContainer.gd @@ -13,12 +13,12 @@ func put_chat(senderdata : SenderData, msg : String): 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(self, "greater") + 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.end - loc.start - 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) @@ -26,9 +26,6 @@ func put_chat(senderdata : SenderData, msg : String): if (bottom): $Chat/ScrollContainer.scroll_vertical = $Chat/ScrollContainer.get_v_scrollbar().max_value -func smaller(a : EmoteLocation, b : EmoteLocation): - return a.start < b.start - class EmoteLocation extends Reference: var id : String var start : int @@ -38,3 +35,6 @@ class EmoteLocation extends Reference: self.id = emote_id self.start = start_idx self.end = end_idx + + static func smaller(a : EmoteLocation, b : EmoteLocation): + return a.start < b.start diff --git a/Gift.gd b/Gift.gd index 3592dc8..241152c 100644 --- a/Gift.gd +++ b/Gift.gd @@ -1,7 +1,19 @@ extends Gift func _ready() -> void: - connect("cmd_no_permission", self, "no_permission") + # 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: + # + # + # + var authfile := File.new() + authfile.open("./auth", 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") @@ -9,31 +21,34 @@ func _ready() -> void: # 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("", "") + authenticate_oauth(botname, token) if(yield(self, "login_attempt") == false): print("Invalid username or token.") return - join_channel("") + join_channel(initial_channel) + + connect("cmd_no_permission", get_parent(), "no_permission") + connect("chat_message", get_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", self, "command_test", 0, 0, PermissionFlag.NON_REGULAR) + add_command("test", get_parent(), "command_test", 0, 0, PermissionFlag.NON_REGULAR) # These two commands can be executed by everyone - add_command("helloworld", self, "hello_world") - add_command("greetme", self, "greet_me") + add_command("helloworld", get_parent(), "hello_world") + add_command("greetme", get_parent(), "greet_me") # This command can only be executed by the streamer - add_command("streamer_only", self, "streamer_only", 0, 0, PermissionFlag.STREAMER) + add_command("streamer_only", get_parent(), "streamer_only", 0, 0, PermissionFlag.STREAMER) # Command that requires exactly 1 arg. - add_command("greet", self, "greet", 1, 1) + add_command("greet", get_parent(), "greet", 1, 1) # Command that prints every arg seperated by a comma (infinite args allowed), at least 2 required - add_command("list", self, "list", -1, 2) + add_command("list", get_parent(), "list", -1, 2) # Adds a command alias add_alias("test","test1") @@ -55,32 +70,10 @@ func _ready() -> void: # Send a chat message to the only connected channel () # Fails, if connected to more than one channel. - chat("TEST") +# chat("TEST") # Send a chat message to channel - chat("TEST", "") +# chat("TEST", initial_channel) # Send a whisper to target user - whisper("TEST", "") - -# 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: - chat("HELLO WORLD!") - -func streamer_only(cmd_info : CommandInfo) -> void: - chat("Streamer command executed") - -func no_permission(cmd_info : CommandInfo) -> void: - chat("NO PERMISSION!") - -func greet(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: - chat("Greetings, " + arg_ary[0]) - -func greet_me(cmd_info : CommandInfo) -> void: - chat("Greetings, " + cmd_info.sender_data.tags["display-name"] + "!") - -func list(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: - chat(arg_ary.join(", ")) \ No newline at end of file +# whisper("TEST", initial_channel) diff --git a/README.md b/README.md index 6e16268..eec9a6b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ Godot IRC For Twitch addon *** +Below is a working example of this plugin, which is included in this project. A replication of the twitch chat. + +![image](https://user-images.githubusercontent.com/12477395/119052327-b9fc9980-b9c4-11eb-8f45-a2a8f2d98977.png) + ### Examples The following code is also [included](https://github.com/MennoMax/gift/blob/master/Gift.gd) in this repository. diff --git a/addons/gift/gift_node.gd b/addons/gift/gift_node.gd index b454c4a..4b76685 100644 --- a/addons/gift/gift_node.gd +++ b/addons/gift/gift_node.gd @@ -81,7 +81,6 @@ func _ready() -> void: websocket.connect("connection_error", self, "connection_error") if(get_images): image_cache = ImageCache.new(disk_cache, disk_cache_path) -# add_child(image_cache) func connect_to_twitch() -> void: if(websocket.connect_to_url("wss://irc-ws.chat.twitch.tv:443") != OK): diff --git a/addons/gift/icon.png b/addons/gift/icon.png index b72c82d..ca073b3 100755 Binary files a/addons/gift/icon.png and b/addons/gift/icon.png differ diff --git a/addons/gift/icon.png.import b/addons/gift/icon.png.import old mode 100755 new mode 100644 diff --git a/icon.png b/icon.png index 2b65815..43962e3 100644 Binary files a/icon.png and b/icon.png differ