Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add irclog search. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions furbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,58 @@
msg.channel.send("https://duckduckgo.com/?q=#{CGI.escape(term)}")
end

on :message, /!log (\A[a-z|A-Z|\d|.|_|-|#|,]{1,20}\z)$/ do |msg, logsearchtext1|
# Showing first newest irclog search result
logresultcounter1 = 0
logfilelist1 = Dir['/logs/plainlogs/*.log'].sort.reverse
logfilelist1.each do |logfilename1|
File.readlines(logfilename1).reverse_each do |filelogline1|
completelogline1 = "#{logfilename1[-14..-5]} #{filelogline1}"
if (completelogline1[logsearchtext1])
logresultcounter1 = logresultcounter1 + 1
msg.channel.send("#{completelogline1}")
exit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A call to #exit will terminate the program (i.e. make furbot quit). I don’t think this is a good idea to use.

end
end
end
if logresultcounter1 == 0 then
msg.channel.send("Not found.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s preferred to use msg.reply, because that’s independant of the way furbot received the message. If someone uses /query on furbot, he will respond properly with a PM in that case again, while using msg.channel.send will always result in a public message in the channel, if any. If the message has no channel (PM), your code will crash here, as msg.channel will be nil.

end
# Cleanup
logresultcounter1 = nil
logfilelist1 = nil
completelogline1 = nil
filelogline1 = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this is necessary. You don’t need to free resources in Ruby :-)

end

on :message, /!lognum (\A[a-z|A-Z|\d|.|_|-|#|,]{1,20}\z) (\A[1-9]{4}\z)$/ do |msg, logsearchtext2, logresultnumber2|
# Showing number x of irclog search result, starting counting from newest first as 1
logresultcounter2 = 0
logresultnumber2i = logresultnumber2.to_i
logfilelist2 = Dir['/logs/plainlogs/*.log'].sort.reverse
logfilelist2.each do |logfilename2|
File.readlines(logfilename2).reverse_each do |filelogline2|
completelogline2 = "#{logfilename2[-14..-5]} #{filelogline2}"
if (completelogline2[logsearchtext2])
logresultcounter2 = logresultcounter2 + 1
if (logresultcounter2 == logresultnumber2i)
msg.channel.send("#{completelogline2}")
exit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before here

end
end
end
end
if logresultcounter2 == 0 then
msg.channel.send("Not found.")
end
# Cleanup
logresultcounter2 = nil
logresultnumber2i = nil
logfilelist2 = nil
completelogline2 = nil
filelogline2 = nil
end

on :message, /!tzconv (.*?) (\w+) to (\w+)$/ do |msg, sourcetimestr, source, target|
# Time.zone_offset only has a few selected zones.
# Let’s add some more.
Expand Down