Compare commits

...

2 commits

Author SHA1 Message Date
e942b41917 Updated Util
Static vars were not being properly created, so instead use a C#
function of '??=', which translates to defining a getter on the
property, checking if it exists, if not, create it and assign it, then
return the value.
Made a duplicate of the string, and did replacements on the new string,
before returning it in html_unescape().
2026-03-09 18:41:40 -05:00
e64855b424 Updated debugger log to not be so spammy 2026-03-09 18:40:07 -05:00
2 changed files with 45 additions and 35 deletions

View file

@ -2,36 +2,47 @@ extends Object
class_name Util class_name Util
#region HTML RegEx and UnEscape HTML #region HTML RegEx and UnEscape HTML
static var _img_re: RegEx = RegEx.create_from_string(r'<img[^>]*src=["\']([^"\']+)["\'][^>]*/?>') static var _img_re: RegEx:
static var _h2_open_re: RegEx = RegEx.create_from_string(r'<h2[^>]*>') get():
static var _p_open_re: RegEx = RegEx.create_from_string(r'<p[^>]*>') if not _img_re: _img_re = RegEx.create_from_string(r'<img[^>]*src=["\']([^"\']+)["\'][^>]*/?>', true)
static var _ul_re: RegEx = RegEx.create_from_string(r'</?ul[^>]*>') return _img_re
static var _div_re: RegEx = RegEx.create_from_string(r'</?div[^>]*>')
static var _any_tag_re: RegEx = RegEx.create_from_string(r'<[^>]*>') static var _h2_open_re: RegEx:
static var _html_replacements: Dictionary[String, String] = { get():
"&lt;": "<", if not _h2_open_re: _h2_open_re = RegEx.create_from_string(r'<h2[^>]*>', true)
"&gt;": ">", return _h2_open_re
"&amp;": "&",
"&quot;": "\"", static var _p_open_re: RegEx:
"&#39;": "'", get():
"&#x27;": "'", if not _p_open_re: _p_open_re = RegEx.create_from_string(r'<p[^>]*>', true)
"&#x2F;": "/", return _p_open_re
"&#96;": "`",
"&nbsp;": " ", static var _ul_re: RegEx:
"&copy;": "©", get():
"&reg;": "®", if not _ul_re: _ul_re = RegEx.create_from_string(r'</?ul[^>]*>', true)
"&euro;": "", return _ul_re
"&pound;": "£",
"&yen;": "¥", static var _div_re: RegEx:
"&ndash;": "", get():
"&mdash;": "", if not _div_re: _div_re = RegEx.create_from_string(r'</?div[^>]*>', true)
"&lsquo;": "", return _div_re
"&rsquo;": "",
"&ldquo;": "", static var _any_tag_re: RegEx:
"&rdquo;": "", get():
"&hellip;": "", if not _any_tag_re: _any_tag_re = RegEx.create_from_string(r'<[^>]*>', true)
"&bull;": "" return _any_tag_re
static var _html_replacements: Dictionary[String, String]:
get():
if not _html_replacements: _html_replacements = {
"&lt;": "<", "&gt;": ">", "&amp;": "&", "&quot;": "\"",
"&#39;": "'", "&#x27;": "'", "&#x2F;": "/", "&#96;": "`",
"&nbsp;": " ", "&copy;": "©", "&reg;": "®", "&euro;": "",
"&pound;": "£", "&yen;": "¥", "&ndash;": "", "&mdash;": "",
"&lsquo;": "", "&rsquo;": "", "&ldquo;": "", "&rdquo;": "",
"&hellip;": "", "&bull;": ""
} }
return _html_replacements
#endregion #endregion
static func convert_html_to_bbcode(html: String) -> String: static func convert_html_to_bbcode(html: String) -> String:
@ -70,9 +81,10 @@ static func convert_html_to_bbcode(html: String) -> String:
static func html_unescape(text: String) -> String: static func html_unescape(text: String) -> String:
for key in _html_replacements.keys(): var new_text: String = String(text)
text = text.replace(key, _html_replacements[key]) for key: String in _html_replacements.keys():
return text new_text = new_text.replace(key, _html_replacements[key])
return new_text
static func resize_img_to_max_dim(img: Image, max_dim: int) -> Image: static func resize_img_to_max_dim(img: Image, max_dim: int) -> Image:
var width: int var width: int

View file

@ -72,9 +72,7 @@ editor/game_oauth_setting="res://addons/twitcher/twitch_oauth_setting.tres"
editor/project_preset=&"Other" editor/project_preset=&"Other"
editor/show_setup_on_startup=false editor/show_setup_on_startup=false
logs/TwitchAuth="debug" logs/TwitchAuth="debug"
logs/TwitchEventsubConfig="debug"
logs/TwitchAPI="debug" logs/TwitchAPI="debug"
logs/TwitchEventsub="debug"
logs/TwitchChat="debug" logs/TwitchChat="debug"
logs/TwitchBot="debug" logs/TwitchBot="debug"
logs/TwitcherExtended="debug" logs/TwitcherExtended="debug"