1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# -*- coding: utf-8 -*-
# This file is part of emesene.
#
# Emesene is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# emesene is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with emesene; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
VERSION = '0.1'
import time
import emesenelib.common
import Plugin
class MainClass(Plugin.Plugin):
'''Main plugin class'''
def __init__(self, controller, msn):
'''Contructor'''
Plugin.Plugin.__init__(self, controller, msn)
self.description = _('Get Last something from the logs')
self.authors = { 'Luis Mariano Guerra' :
'luismarianoguerra at gmail dot com' }
self.website = 'http://emesene.org'
self.displayName = 'LastStuff'
self.name = 'LastStuff'
self.controller = controller
self.Slash = controller.Slash
def start(self):
'''start the plugin'''
self.Slash.register('last', self.get_last, 'Get last stuff')
self.enabled = True
def get_last(self, slash_action):
params = slash_action.getParams()
if params:
data = params.split(' ')
else:
data = ''
logger = self.controller.pluginManager.getPlugin("Logger")
if not logger or not logger.enabled:
slash_action.outputText('Logger plugin not available', False)
return
if len(data) != 3:
slash_action.outputText('Usage: /last # stuff account', False)
return
(stamp, stuff, account) = data
try:
num = int(data[0])
except:
slash_action.outputText(_('invalid number as first parameter'),
False)
return
if data[1] == "nick":
results = logger.get_last_nick(account, num)
results.reverse()
for (stamp, result) in results:
slash_action.outputText(result, False)
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
elif data[1] == "pm":
results = logger.get_last_personal_message(account, num)
results.reverse()
for (stamp, result) in results:
slash_action.outputText(result, False)
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
elif data[1] == "ce":
results = logger.get_last_custom_emoticon(account, num)
results.reverse()
for (stamp, result) in results:
slash_action.outputText(result, False)
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
elif data[1] == "dp":
results = logger.get_last_display_picture(account, num)
results.reverse()
for (stamp, result) in results:
slash_action.outputText(result, False)
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
elif data[1] == "message":
results = logger.get_last_message(account, num)
results.reverse()
for (stamp, result) in results:
try:
slash_action.outputText(result.split("\r\n")[2], False)
except IndexError:
print 'malformed message on LastStuff'
if len(results) == 0:
slash_action.outputText('Empty result', False)
elif data[1] == "conversation":
results = logger.get_last_conversation(account, num)
results.reverse()
for (stamp, account, result) in results:
try:
slash_action.outputText(
account + ': ' + result.split("\r\n")[2], False)
except IndexError:
print 'malformed message on LastStuff'
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
elif data[1] == "status":
results = logger.get_last_status(account, num)
results.reverse()
for (stamp, result) in results:
slash_action.outputText('%s since %s' % (
emesenelib.common.reverse_status[result],
time.ctime(float(stamp)))
, False)
if len(results) == 0:
slash_action.outputText(_('Empty result'), False)
def stop(self):
'''stop the plugin'''
self.Slash.unregister('last')
self.enabled = False
def check(self):
plugin = self.controller.pluginManager.getPlugin("Logger")
if plugin is None or not plugin.enabled:
return (False, _('Enable the logger plugin'))
return (True, 'Ok')
|