diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5a749fd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf + +# Ignore some files when exporting. +/.github export-ignore +/.gitattributes export-ignore +/default_env.tres export-ignore +/icon.png export-ignore +/icon.png.import export-ignore +/project.godot export-ignore +/README.md export-ignore diff --git a/.github/workflows/file_format.sh b/.github/workflows/file_format.sh new file mode 100755 index 0000000..5eedbac --- /dev/null +++ b/.github/workflows/file_format.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# This script ensures proper POSIX text file formatting and a few other things. + +# We need dos2unix and recode. +if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then + printf "Install 'dos2unix' and 'recode' to use this script.\n" +fi + +set -uo pipefail +IFS=$'\n\t' + +# Loops through all text files tracked by Git. +git grep -zIl '' | +while IFS= read -rd '' f; do + # Exclude some files. + if [[ "$f" == *"csproj"* ]]; then + continue + fi + # Ensure that files are UTF-8 formatted. + recode UTF-8 "$f" 2> /dev/null + # Ensure that files have LF line endings and do not contain a BOM. + dos2unix "$f" 2> /dev/null + # Remove trailing space characters and ensures that files end + # with newline characters. -l option handles newlines conveniently. + perl -i -ple 's/\s*$//g' "$f" + # We don't want to change lines around braces in godot/tscn files. + if [[ "$f" == *"godot" ]]; then + continue + elif [[ "$f" == *"tscn" ]]; then + continue + fi +done + +git diff > patch.patch + +# If no patch has been generated all is OK, clean up, and exit. +if [ ! -s patch.patch ] ; then + printf "Files in this commit comply with the formatting rules.\n" + rm -f patch.patch + exit 0 +fi + +# A patch has been created, notify the user, clean up, and exit. +printf "\n*** The following differences were found between the code " +printf "and the formatting rules:\n\n" +cat patch.patch +printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i '\n" +rm -f patch.patch +exit 1 diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml new file mode 100644 index 0000000..b8bd5e3 --- /dev/null +++ b/.github/workflows/static_checks.yml @@ -0,0 +1,19 @@ +name: 📊 Static Checks +on: [push, pull_request] + +jobs: + format: + name: File formatting (file_format.sh) + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -qq dos2unix recode + + - name: File formatting checks (file_format.sh) + run: | + bash ./.github/workflows/file_format.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bded6b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Godot 4+ specific ignores +.godot/ + +# Godot-specific ignores +.import/ + +# Imported translations (automatically generated from CSV files) +*.translation + +# Mono-specific ignores +.mono/ +data_*/ +mono_crash.*.json + +# System/tool-specific ignores +.directory +*~ diff --git a/ChatContainer.gd b/ChatContainer.gd index d98a390..09aa1ea 100644 --- a/ChatContainer.gd +++ b/ChatContainer.gd @@ -30,7 +30,7 @@ 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 diff --git a/Gift.gd b/Gift.gd index 241152c..36ab56c 100644 --- a/Gift.gd +++ b/Gift.gd @@ -13,10 +13,10 @@ func _ready() -> void: 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/ @@ -26,27 +26,27 @@ func _ready() -> void: print("Invalid username or token.") return 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", get_parent(), "command_test", 0, 0, PermissionFlag.NON_REGULAR) - + # These two commands can be executed by everyone 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", get_parent(), "streamer_only", 0, 0, PermissionFlag.STREAMER) - + # Command that requires exactly 1 arg. 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", get_parent(), "list", -1, 2) @@ -56,10 +56,10 @@ func _ready() -> void: 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" @@ -67,13 +67,13 @@ func _ready() -> void: # 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 () # Fails, if connected to more than one channel. # chat("TEST") - + # Send a chat message to channel # chat("TEST", initial_channel) - + # Send a whisper to target user # whisper("TEST", initial_channel) diff --git a/README.md b/README.md index eec9a6b..62dc4f1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ func _ready() -> void: connect("cmd_no_permission", self, "no_permission") 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/ @@ -34,24 +34,24 @@ func _ready() -> void: print("Invalid username or token.") return join_channel() - + # 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) - + # These two commands can be executed by everyone add_command("helloworld", self, "hello_world") add_command("greetme", self, "greet_me") - + # This command can only be executed by the streamer add_command("streamer_only", self, "streamer_only", 0, 0, PermissionFlag.STREAMER) - + # Command that requires exactly 1 arg. add_command("greet", self, "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) @@ -61,10 +61,10 @@ func _ready() -> void: 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" @@ -72,14 +72,14 @@ func _ready() -> void: # 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 () # Fails, if connected to more than one channel. chat("TEST") - + # Send a chat message to channel chat("TEST", ) - + # Send a whisper to target user whisper("TEST", ) @@ -104,7 +104,7 @@ func greet_me(cmd_info : CommandInfo) -> void: func list(cmd_info : CommandInfo, arg_ary : PoolStringArray) -> void: chat(arg_ary.join(", ")) - + ``` *** diff --git a/addons/gift/gift_node.gd b/addons/gift/gift_node.gd index 4b76685..0d3690f 100644 --- a/addons/gift/gift_node.gd +++ b/addons/gift/gift_node.gd @@ -208,7 +208,7 @@ func handle_command(sender_data : SenderData, msg : PoolStringArray, whisper : b if(whisper == true && cmd_data.where & WhereFlag.WHISPER != WhereFlag.WHISPER): return elif(whisper == false && cmd_data.where & WhereFlag.CHAT != WhereFlag.CHAT): - return + return var args = "" if msg.size() < 5 else msg[4] var arg_ary : PoolStringArray = PoolStringArray() if args == "" else args.split(" ") if(arg_ary.size() > cmd_data.max_args && cmd_data.max_args != -1 || arg_ary.size() < cmd_data.min_args): diff --git a/addons/gift/icon.png b/addons/gift/icon.png index ca073b3..73b70ff 100755 Binary files a/addons/gift/icon.png and b/addons/gift/icon.png differ diff --git a/addons/gift/placeholder.png b/addons/gift/placeholder.png index 35719d5..c156f90 100644 Binary files a/addons/gift/placeholder.png and b/addons/gift/placeholder.png differ diff --git a/addons/gift/util/cmd_data.gd b/addons/gift/util/cmd_data.gd index c3237b3..cbf3663 100644 --- a/addons/gift/util/cmd_data.gd +++ b/addons/gift/util/cmd_data.gd @@ -13,4 +13,4 @@ func _init(f_ref : FuncRef, perm_lvl : int, mx_args : int, mn_args : int, whr : max_args = mx_args min_args = mn_args where = whr - + diff --git a/addons/gift/util/cmd_info.gd b/addons/gift/util/cmd_info.gd index a7a5ab3..82dad4b 100644 --- a/addons/gift/util/cmd_info.gd +++ b/addons/gift/util/cmd_info.gd @@ -9,4 +9,4 @@ func _init(sndr_dt, cmd, whspr): sender_data = sndr_dt command = cmd whisper = whspr - + diff --git a/addons/gift/util/image_cache.gd b/addons/gift/util/image_cache.gd index 0260fad..9e29b6d 100644 --- a/addons/gift/util/image_cache.gd +++ b/addons/gift/util/image_cache.gd @@ -187,7 +187,7 @@ class Entry extends Reference: var type : int var filename : String var data : Array - + func _init(path : String, type : int, filename : String, data : Array): self.path = path self.type = type diff --git a/icon.png b/icon.png index 43962e3..4a866c8 100644 Binary files a/icon.png and b/icon.png differ