add .deletethis to NSFW module

master
an 2020-01-25 17:37:28 -05:00
parent 9c20aabb84
commit 0af5981abe
1 changed files with 17 additions and 4 deletions

View File

@ -8,12 +8,16 @@ class Mod_NSFW < Vrobot4::Module::Module
def initialize info def initialize info
super super
register :c_danbooru, "danbooru", "Queries Danbooru for a random image." register :c_danbooru, "danbooru", "Queries Danbooru for an image."
register :c_saucenao, "saucenao", "Queries SauceNao for an image." register :c_saucenao, "saucenao", "Queries SauceNao for an image."
register :c_deletethis, "deletethis", "Deletes the last image by you."
@disallowed = info[:danbooru_filters] @disallowed = info[:danbooru_filters]
@danbooru_login = info[:danbooru_login] @danbooru_login = info[:danbooru_login]
@danbooru_api_key = info[:danbooru_api_key] @danbooru_api_key = info[:danbooru_api_key]
@saucenao_api_key = info[:saucenao_api_key] @saucenao_api_key = info[:saucenao_api_key]
@culling_cache = {}
end end
def c_danbooru m, argv def c_danbooru m, argv
@ -30,7 +34,7 @@ class Mod_NSFW < Vrobot4::Module::Module
api_key: @danbooru_api_key, api_key: @danbooru_api_key,
} }
parm[:tags] = argv unless argv.empty? parm[:tags] = argv unless argv.empty?
uri = URI("https://danbooru.donmai.us/posts.json") uri = URI "https://danbooru.donmai.us/posts.json"
uri.query = URI.encode_www_form parm uri.query = URI.encode_www_form parm
res = Net::HTTP.get_response(uri) res = Net::HTTP.get_response(uri)
@ -42,7 +46,7 @@ class Mod_NSFW < Vrobot4::Module::Module
src = obj["source"] src = obj["source"]
src = "none provided" if src.empty? src = "none provided" if src.empty?
if !tags.match(disallow_regex) && url && !url.empty? if !tags.match(disallow_regex) && url && !url.empty?
m.reply "#{url}\n(source: <#{src}>)" @culling_cache[m.user.id] = m.reply "#{url}\n(source: <#{src}>)"
return return
end end
end end
@ -76,6 +80,15 @@ class Mod_NSFW < Vrobot4::Module::Module
raise ArgumentError, "Couldn't process request. Error code: #{res}" raise ArgumentError, "Couldn't process request. Error code: #{res}"
end end
end end
def c_deletethis m, argv
if cull = @culling_cache[m.user.id]
m.real.delete
cull.delete
else
m.reply "No images to delete."
end
end
end end
## EOF ## EOF