Class: Muzang::Plugins::Grep
- Inherits:
-
Object
- Object
- Muzang::Plugins::Grep
- Includes:
- Helpers
- Defined in:
- lib/muzang-plugins/muzang-grep.rb
Defined Under Namespace
Classes: Message
Constant Summary collapse
- DATABASE_FILE =
'irclog.sqlite3'
- DATABASE_CONFIG =
{ :database => 'irclog.sqlite3', :encoding => 'utf8', :adapter => 'sqlite3' }
Instance Method Summary collapse
- #call(connection, message) ⇒ Object
-
#initialize(bot) ⇒ Grep
constructor
A new instance of Grep.
- #persist_message(message) ⇒ Object
- #search_for_term(connection, message, term) ⇒ Object
Methods included from Helpers
#create_database, #match, #on_channel, #on_join
Constructor Details
#initialize(bot) ⇒ Grep
Returns a new instance of Grep.
43 44 45 46 |
# File 'lib/muzang-plugins/muzang-grep.rb', line 43 def initialize(bot) @bot = bot open_database end |
Instance Method Details
#call(connection, message) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/muzang-plugins/muzang-grep.rb', line 48 def call(connection, ) on_channel() do match(, /^[^~(Searched)]/) do () end match(, /^~ (.*)/) do |what| search_for_term(connection, , what[1]) end end rescue puts $! puts $!.backtrace raise end |
#persist_message(message) ⇒ Object
63 64 65 66 67 |
# File 'lib/muzang-plugins/muzang-grep.rb', line 63 def () Message.create!(:channel => .channel, :user => .user, :content => .) end |
#search_for_term(connection, message, term) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/muzang-plugins/muzang-grep.rb', line 69 def search_for_term(connection, , term) results = Message.like(.channel, term) if results.size > 0 link = save_results(term, results) connection.msg(.channel, "Searched for '#{term}', found #{results.size} matches: #{link}") else connection.msg(.channel, "Searched for '#{term}', nothing found") end end |