fix link logic
This commit is contained in:
parent
d3e337aa25
commit
964aaaaed6
17
main.rb
17
main.rb
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
require 'bundler/setup'
|
#require 'bundler/setup'
|
||||||
require 'discordrb'
|
require 'discordrb'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'mimemagic'
|
require 'mimemagic'
|
||||||
@ -65,8 +65,10 @@ end
|
|||||||
bot.message(private: true) do |event|
|
bot.message(private: true) do |event|
|
||||||
sender = event.author.id
|
sender = event.author.id
|
||||||
i = 1
|
i = 1
|
||||||
|
updated = false
|
||||||
event.message.attachments.each do |file|
|
event.message.attachments.each do |file|
|
||||||
res = MimeMagic.by_path(file.filename)
|
res = MimeMagic.by_path(file.filename)
|
||||||
|
updated = true
|
||||||
if res != nil
|
if res != nil
|
||||||
if res.image? or res.video?
|
if res.image? or res.video?
|
||||||
download = Down.download(file.url)
|
download = Down.download(file.url)
|
||||||
@ -81,7 +83,6 @@ bot.message(private: true) do |event|
|
|||||||
event.respond("Submission denied; attached file but I can't figure out the file type")
|
event.respond("Submission denied; attached file but I can't figure out the file type")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
error = false
|
|
||||||
urls = URI.extract(event.content)
|
urls = URI.extract(event.content)
|
||||||
urls.each do |url|
|
urls.each do |url|
|
||||||
mime_guess = MimeMagic.by_extension(url)
|
mime_guess = MimeMagic.by_extension(url)
|
||||||
@ -90,19 +91,23 @@ bot.message(private: true) do |event|
|
|||||||
download = Down.download(file.url)
|
download = Down.download(file.url)
|
||||||
FileUtils.mv(download.path, "./spool/#{download.original_filename}")
|
FileUtils.mv(download.path, "./spool/#{download.original_filename}")
|
||||||
folder.submit(Submission.new("./spool/#{download.original_filename}",true,sender))
|
folder.submit(Submission.new("./spool/#{download.original_filename}",true,sender))
|
||||||
|
event.respond("Submission #{i} accepted")
|
||||||
|
updated = true
|
||||||
else
|
else
|
||||||
event.respond("Submission denied; link goes to a piece of media but I can't figure out what it is")
|
event.respond("Submission denied; link goes to a piece of media but I can't figure out what it is")
|
||||||
error = true
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
folder.submit(Submission.new(url,false,sender))
|
folder.submit(Submission.new(url,false,sender))
|
||||||
end
|
|
||||||
if error
|
|
||||||
event.respond("Submission #{i} accepted")
|
event.respond("Submission #{i} accepted")
|
||||||
|
updated = true
|
||||||
end
|
end
|
||||||
i= i+1
|
i= i+1
|
||||||
end
|
end
|
||||||
folder.update()
|
if updated
|
||||||
|
folder.update()
|
||||||
|
else
|
||||||
|
event.respond("Submission denied: I don't know what this is")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#set up signals
|
#set up signals
|
||||||
|
Loading…
Reference in New Issue
Block a user