Skip to content

Commit

Permalink
Merge pull request #6963 from MahtraDR/dependency_status
Browse files Browse the repository at this point in the history
[scripts][dependency] Add repository fallback functionality
  • Loading branch information
MahtraDR authored Oct 30, 2024
2 parents 4a07341 + 6873ea1 commit 8eca738
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions dependency.lic
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8eca738

Please sign in to comment.