Added /grep command. Fixes #5438
This commit is contained in:
parent
750fbc844d
commit
909ef8da53
1 changed files with 44 additions and 0 deletions
|
@ -17,10 +17,14 @@
|
|||
Provides an actual implementation for the standard commands.
|
||||
"""
|
||||
|
||||
from time import localtime, strftime
|
||||
from datetime import date
|
||||
|
||||
import dialogs
|
||||
from common import gajim
|
||||
from common import helpers
|
||||
from common.exceptions import GajimGeneralException
|
||||
from common.logger import Constants
|
||||
|
||||
from ..errors import CommandError
|
||||
from ..framework import CommandContainer, command, documentation
|
||||
|
@ -28,6 +32,10 @@ from ..mapping import generate_usage
|
|||
|
||||
from hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
|
||||
|
||||
# This holds constants fron the logger, which we'll be using in some of our
|
||||
# commands.
|
||||
lc = Constants()
|
||||
|
||||
class StandardCommonCommands(CommandContainer):
|
||||
"""
|
||||
This command container contains standard commands which are common to all -
|
||||
|
@ -84,6 +92,42 @@ class StandardCommonCommands(CommandContainer):
|
|||
def me(self, action):
|
||||
self.send("/me %s" % action)
|
||||
|
||||
@command('lastlog', overlap=True)
|
||||
@documentation(_("Show logged messages which mention given text"))
|
||||
def grep(self, text, limit=None):
|
||||
results = gajim.logger.get_search_results_for_query(self.contact.jid,
|
||||
text, self.account)
|
||||
|
||||
if not results:
|
||||
raise CommandError(_("%s: Nothing found") % text)
|
||||
|
||||
if limit:
|
||||
try:
|
||||
results = results[len(results) - int(limit):]
|
||||
except ValueError:
|
||||
raise CommandError(_("Limit must be an integer"))
|
||||
|
||||
for row in results:
|
||||
contact, time, kind, show, message, subject = row
|
||||
|
||||
if not contact:
|
||||
if kind == lc.KIND_CHAT_MSG_SENT:
|
||||
contact = gajim.nicks[self.account]
|
||||
else:
|
||||
contact = self.contact.name
|
||||
|
||||
time_obj = localtime(time)
|
||||
date_obj = date.fromtimestamp(time)
|
||||
date_ = strftime('%Y-%m-%d', time_obj)
|
||||
time_ = strftime('%H:%M:%S', time_obj)
|
||||
|
||||
if date_obj == date.today():
|
||||
formatted = "[%s] %s: %s" % (time_, contact, message)
|
||||
else:
|
||||
formatted = "[%s, %s] %s: %s" % (date_, time_, contact, message)
|
||||
|
||||
self.echo(formatted)
|
||||
|
||||
class StandardChatCommands(CommandContainer):
|
||||
"""
|
||||
This command container contains standard command which are unique to a chat.
|
||||
|
|
Loading…
Add table
Reference in a new issue