Browse Source

add .deletethis to NSFW module

master
Alison Watson 1 month ago
parent
commit
0af5981abe
1 changed files with 17 additions and 4 deletions
  1. +17
    -4
      source/modules/nsfw.rb

+ 17
- 4
source/modules/nsfw.rb View File

@@ -8,12 +8,16 @@ class Mod_NSFW < Vrobot4::Module::Module

def initialize info
super
register :c_danbooru, "danbooru", "Queries Danbooru for a random image."
register :c_saucenao, "saucenao", "Queries SauceNao for an image."
register :c_danbooru, "danbooru", "Queries Danbooru 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]
@danbooru_login = info[:danbooru_login]
@danbooru_api_key = info[:danbooru_api_key]
@saucenao_api_key = info[:saucenao_api_key]

@culling_cache = {}
end

def c_danbooru m, argv
@@ -30,7 +34,7 @@ class Mod_NSFW < Vrobot4::Module::Module
api_key: @danbooru_api_key,
}
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

res = Net::HTTP.get_response(uri)
@@ -42,7 +46,7 @@ class Mod_NSFW < Vrobot4::Module::Module
src = obj["source"]
src = "none provided" if src.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
end
end
@@ -76,6 +80,15 @@ class Mod_NSFW < Vrobot4::Module::Module
raise ArgumentError, "Couldn't process request. Error code: #{res}"
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

## EOF

Loading…
Cancel
Save