Compare commits

...

2 Commits

Author SHA1 Message Date
an 0af5981abe add .deletethis to NSFW module 2020-01-25 17:37:28 -05:00
an 9c20aabb84 add "real" field to Vrobot4::Server::Message 2020-01-25 17:37:15 -05:00
3 changed files with 22 additions and 5 deletions

View File

@ -170,7 +170,8 @@ module Backend_Discord
serv: serv, serv: serv,
bot: self, bot: self,
reply: -> (text) {evt.channel.send text}, reply: -> (text) {evt.channel.send text},
reply_b: -> (text) {evt.channel.send "```\n#{text}```"} reply_b: -> (text) {evt.channel.send "```\n#{text}```"},
real: evt.message
serv.handle_text_cmd m serv.handle_text_cmd m
end end

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

View File

@ -22,6 +22,7 @@ module Vrobot4::Server
attr_reader :chan # @return [Channel] channel this message was sent to attr_reader :chan # @return [Channel] channel this message was sent to
attr_reader :serv # @return [Server] server this message was sent to attr_reader :serv # @return [Server] server this message was sent to
attr_reader :bot # @return [Vrobot4::Robots::Bot] bot this was sent to attr_reader :bot # @return [Vrobot4::Robots::Bot] bot this was sent to
attr_reader :real # @return the original message, if any
# @param info [Hash] A hash containing message info. Keys may be omitted. # @param info [Hash] A hash containing message info. Keys may be omitted.
# [:msg] Plaintext of message. # [:msg] Plaintext of message.
@ -31,6 +32,7 @@ module Vrobot4::Server
# [:bot] Bot this message was sent to. # [:bot] Bot this message was sent to.
# [:reply] Method that sends a message to the specified channel. # [:reply] Method that sends a message to the specified channel.
# [:reply_b] Method that sends a large message to the specified channel. # [:reply_b] Method that sends a large message to the specified channel.
# [:real] The original message, if any.
def initialize(**info) def initialize(**info)
@msg = info[:msg] @msg = info[:msg]
@user = info[:user] @user = info[:user]
@ -39,6 +41,7 @@ module Vrobot4::Server
@bot = info[:bot] @bot = info[:bot]
@reply = info[:reply] @reply = info[:reply]
@reply_b = info[:reply_b] @reply_b = info[:reply_b]
@real = info[:real]
end end
# Sends a message to the originating channel. # Sends a message to the originating channel.