discord: add /tagme command.

This commit is contained in:
evazion
2021-03-19 04:44:22 -05:00
parent cebfe3308e
commit 1a7a108d47
8 changed files with 231 additions and 14 deletions

View File

@@ -11,8 +11,9 @@ require "danbooru/http/unpolish_cloudflare"
module Danbooru
class Http
class DownloadError < StandardError; end
class FileTooLargeError < StandardError; end
class Error < StandardError; end
class DownloadError < Error; end
class FileTooLargeError < Error; end
DEFAULT_TIMEOUT = 10
MAX_REDIRECTS = 5
@@ -43,7 +44,7 @@ module Danbooru
end
def put(url, **options)
request(:get, url, **options)
request(:put, url, **options)
end
def post(url, **options)
@@ -54,6 +55,14 @@ module Danbooru
request(:delete, url, **options)
end
def get!(url, **options)
request!(:get, url, **options)
end
def post!(url, **options)
request!(:post, url, **options)
end
def follow(*args)
dup.tap { |o| o.http = o.http.follow(*args) }
end
@@ -136,6 +145,16 @@ module Danbooru
fake_response(599, "")
end
def request!(method, url, **options)
response = request(method, url, **options)
if response.status.in?(200..399)
response
else
raise Error, "#{method.upcase} #{url} failed (HTTP #{response.status})"
end
end
def fake_response(status, body)
::HTTP::Response.new(status: status, version: "1.1", body: ::HTTP::Response::Body.new(body))
end