Skip to content

Commit

Permalink
Update README.md, missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
issork committed May 21, 2021
1 parent b107c49 commit 65aacbc
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 46 deletions.
3 changes: 0 additions & 3 deletions .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5

This file was deleted.

Binary file not shown.
3 changes: 0 additions & 3 deletions .import/icon.png-b5cf707f4ba91fefa5df60a746e02900.md5

This file was deleted.

Binary file removed .import/icon.png-b5cf707f4ba91fefa5df60a746e02900.stex
Binary file not shown.
10 changes: 5 additions & 5 deletions ChatContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ 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)
yield(get_tree(), "idle_frame")
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
Expand All @@ -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
61 changes: 27 additions & 34 deletions Gift.gd
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
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:
# <bot username>
# <oauth token>
# <initial channel>
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")

# 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("<account_name>", "<oauth_token>")
authenticate_oauth(botname, token)
if(yield(self, "login_attempt") == false):
print("Invalid username or token.")
return
join_channel("<channel_name>")
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")
Expand All @@ -55,32 +70,10 @@ func _ready() -> void:

# Send a chat message to the only connected channel (<channel_name>)
# Fails, if connected to more than one channel.
chat("TEST")
# chat("TEST")

# Send a chat message to channel <channel_name>
chat("TEST", "<channel_name>")
# chat("TEST", initial_channel)

# Send a whisper to target user
whisper("TEST", "<target_name>")

# 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(", "))
# whisper("TEST", initial_channel)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion addons/gift/gift_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Binary file modified addons/gift/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified addons/gift/icon.png.import
100755 → 100644
Empty file.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 65aacbc

Please sign in to comment.