From ae680f27024b08c010976b9e29412828348048ed Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@gmail.com> Date: Sat, 5 Jan 2013 18:34:24 +0100 Subject: [PATCH] Tag are inserted into bdd --- lib/playbot.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/playbot.rb b/lib/playbot.rb index 96343be..d214150 100644 --- a/lib/playbot.rb +++ b/lib/playbot.rb @@ -5,7 +5,9 @@ require 'bundler/setup' require 'net/yail/irc_bot' require_relative 'site_plugin.rb' +require_relative 'tag_parser.rb' require_relative 'music.rb' +require_relative 'tag.rb' # -- @@ -80,13 +82,27 @@ class PlayBot < IRCBot return if handler.nil? content = handler.new(@options).get(url) - music = Music.create( - :title => content[:title], - :author => content[:author], - :sender => event.nick, - :url => content[:url], - :file => nil) - + + music = Music.find_by_url(content[:url]) + music ||= Music.create( + :title => content[:title], + :author => content[:author], + :sender => event.nick, + :url => content[:url], + :file => nil + ) + + tags = TagParser.parse! event.message + puts tags + tags.each do |tag| + if !Tag.exists?(:video => music.id, :tag => tag) + Tag.create( + :video => music.id, + :tag => tag + ) + end + end + msg(event.channel, "#{music.title} | #{music.author}") end end -- GitLab