From 6873ea1887c64816cb7beac8db3cd8d4ca628afe Mon Sep 17 00:00:00 2001 From: Mahtra Date: Wed, 30 Oct 2024 13:09:53 +1300 Subject: [PATCH] Now we catch invalid URIs --- dependency.lic | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/dependency.lic b/dependency.lic index 484eb47809..6d96fca2ad 100644 --- a/dependency.lic +++ b/dependency.lic @@ -10,7 +10,7 @@ require 'ostruct' require 'digest/sha1' require 'monitor' -$DEPENDENCY_VERSION = '1.7.4' +$DEPENDENCY_VERSION = '1.7.5' $MIN_RUBY_VERSION = '3.2.2' DRINFOMON_IN_CORE_LICH ||= false @@ -242,7 +242,44 @@ class ScriptManager end def update_status_url - @status_url = 'https://api.github.com/repos/' + @status_repo + '/git/trees/' + @status_branch + defaulturl = 'https://api.github.com/repos/' + @status_repo + '/git/trees/' + @status_branch + mainurl = 'https://api.github.com/repos/rpherbig/dr-scripts/git/trees/main' + fallbackurl = 'https://api.github.com/repos/rpherbig/dr-scripts/git/trees/master' + eo_drscripts = 'https://api.github.com/repos/elanthia-online/dr-scripts/git/trees/main' + + unless url_exist?(defaulturl) + _respond Lich::Messaging.monsterbold("Default URL #{defaulturl} not responding. Using an alternate repo+branch combindation.") + _respond Lich::Messaging.monsterbold("Unsetting custom repo settings, if any.") + Settings['status_repo'] = nil if Settings['status_repo'] + Settings['status_branch'] = nil if Settings['status_branch'] + end + + if url_exist?(defaulturl) + @status_url = defaulturl + _respond Lich::Messaging.monsterbold("Using set Status URL. #{defaulturl}") + elsif url_exist?(mainurl) + _respond Lich::Messaging.monsterbold("Using alternate Status URL. #{mainurl}") + @status_url = mainurl + elsif url_exist?(fallbackurl) + _respond Lich::Messaging.monsterbold("Using fallback Status URL. #{fallbackurl}") + @status_url = fallbackurl + elsif url_exist?(eo_drscripts) + _respond Lich::Messaging.monsterbold("Using Elanthia Online Status URL. #{eo_drscripts}") + @status_url = eo_drscripts + else + _respond Lich::Messaging.monsterbold("Could not set Status URL. Please seek help on Discord.") + end + end + + def url_exist?(url_string) + url = URI.parse(url_string) + req = Net::HTTP.new(url.host, url.port) + req.use_ssl = (url.scheme == 'https') + path = url.path + res = req.request_head(path || '/') + res.code != "404" # false if returns 404 - not found + rescue Errno::ENOENT, URI::InvalidURIError + false # false if can't find the server, or URI invalid somehow end def set_custom_status_repo(repo, branch)