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