Compare commits
2 Commits
d1e1ecdb19
...
0af5981abe
Author | SHA1 | Date |
---|---|---|
an | 0af5981abe | |
an | 9c20aabb84 |
|
@ -170,7 +170,8 @@ module Backend_Discord
|
|||
serv: serv,
|
||||
bot: self,
|
||||
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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,6 +22,7 @@ module Vrobot4::Server
|
|||
attr_reader :chan # @return [Channel] channel 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 :real # @return the original message, if any
|
||||
|
||||
# @param info [Hash] A hash containing message info. Keys may be omitted.
|
||||
# [:msg] Plaintext of message.
|
||||
|
@ -31,6 +32,7 @@ module Vrobot4::Server
|
|||
# [:bot] Bot this message was sent to.
|
||||
# [:reply] Method that sends a 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)
|
||||
@msg = info[:msg]
|
||||
@user = info[:user]
|
||||
|
@ -39,6 +41,7 @@ module Vrobot4::Server
|
|||
@bot = info[:bot]
|
||||
@reply = info[:reply]
|
||||
@reply_b = info[:reply_b]
|
||||
@real = info[:real]
|
||||
end
|
||||
|
||||
# Sends a message to the originating channel.
|
||||
|
|
Loading…
Reference in New Issue