1 # -*- coding: utf-8 -*-
2 '''A plug-in that "imitates" someone. It will copy nick, message, picture
3 from that person and auto-update it. Not so useful, but very funny! ;-)
12 #import emesenelib.common
17 class MainClass( Plugin
.Plugin
):
18 '''Main plugin class'''
19 def __init__(self
, controller
, msn
):
21 Plugin
.Plugin
.__init
__( self
, controller
, msn
)
22 self
.description
= _('Copy nick, PM, image and status from someone and autoupdates')
23 self
.authors
= { 'BoySka' : 'boyska gmail com' }
24 self
.website
= 'http://emesene.org'
25 self
.displayName
= _('Imitate')
29 self
.controller
= controller
32 self
.user
= None #user we are imitating
33 self
.saved_status
= {}
35 self
.cb_ids
= {} #callback ids
40 '''start the plugin'''
41 #self._set_nick("prova")
42 self
.controller
.Slash
.register('imitate', self
.slash_imitate
,
43 _('Imitates someone'))
45 self
.cb_ids
['nick-changed'] = self
.connect(
46 'nick-changed', self
.on_nick_changed
)
47 self
.cb_ids
['message-changed'] = self
.connect(
48 'personal-message-changed', self
.on_message_changed
)
49 self
.cb_ids
['picture-changed'] = self
.connect(
50 'display-picture-changed', self
.on_picture_changed
)
56 self
.controller
.Slash
.unregister('imitate')
57 self
.disconnect(self
.cb_ids
['nick-changed'])
58 self
.disconnect(self
.cb_ids
['message-changed'])
59 self
.disconnect(self
.cb_ids
['picture-changed'])
63 '''check if the plugin can be enabled'''
67 def slash_imitate(self
, slash_action
):
68 '''callback used when /imitate is used'''
73 if slash_action
.params
== 'stop':
78 if not slash_action
.params
:
79 user
= slash_action
.conversation
.getMembers()[0]
81 user
= slash_action
.params
85 self
._imitate
_nick
(user
)
86 self
._imitate
_message
(user
)
87 self
._imitate
_status
(user
)
88 self
._imitate
_picture
(user
)
90 def on_nick_changed(self
, msn
, user
, nick
):
91 '''callback used when someone changes his nick'''
92 if user
and user
== self
.user
:
95 def on_message_changed(self
, msn
, user
, message
):
96 '''callback used when someone changes his message'''
97 if user
and user
== self
.user
:
99 self
._set
_message
(message
)
101 def on_picture_changed(self
, msn
, user
, creator
, email
):
102 '''callback used when someone changes his picture'''
103 if user
and user
== self
.user
:
105 self
._imitate
_picture
(email
)
109 def _save_status(self
):
110 '''saves user nick, message and picture in self.saved_status'''
111 saved
= self
.saved_status
112 saved
['nick'] = self
.controller
.contacts
.get_nick()
113 saved
['message'] = self
.controller
.contacts
.get_message()
114 saved
['picture'] = self
.controller
.avatar
.getImagePath()
115 #saved['status'] = status.STATUS_TO_MSN[self.controller.contacts.get_status()]
116 saved
['status'] = self
.controller
.contacts
.get_status() or 'NLN'
118 def _revert_status(self
):
119 '''set nick, message and picture to the ones
120 saved in self.saved_status'''
121 saved
= self
.saved_status
122 self
._set
_nick
(saved
['nick'])
123 self
._set
_message
(saved
['message'])
124 #self._set_picture(os.path.join(
125 # self.controller.config.getAvatarsCachePath(),
127 self
._set
_picture
(saved
['picture'])
128 self
._set
_status
(saved
['status'])
131 def _imitate_nick(self
, user
):
132 '''imitates the nick of user'''
133 nick
= self
.controller
.contacts
.get_nick(user
)
136 def _imitate_message(self
, user
):
137 '''imitates the message of user'''
138 contact
= self
.msn
.contactManager
.getContact(user
)
139 message
= contact
.personalMessage
141 self
._set
_message
(message
)
143 def _imitate_status(self
, user
):
144 '''imitates the status of user'''
145 contact
= self
.msn
.contactManager
.getContact(user
)
146 stat
= contact
.status
148 self
._set
_status
(stat
)
150 def _imitate_picture(self
, user
):
151 '''imitates the message of user'''
152 contact
= self
.msn
.contactManager
.getContact(user
)
153 picture
= contact
.displayPicturePath
155 picture_path
= os
.path
.join(
156 self
.controller
.config
.getCachePath(), picture
)
157 self
._set
_picture
(picture_path
)
159 def _set_message(self
, message
):
160 '''set our message to message'''
161 self
.controller
.contacts
.set_message(message
)
163 def _set_status(self
, status
):
164 '''set our status to status'''
165 self
.controller
.contacts
.set_status(status
)
167 def _set_picture(self
, picture_path
):
168 '''set our picture to picture_path'''
169 self
.controller
.changeAvatar(picture_path
)
171 def _set_nick(self
, nick
):
172 '''set our nick to nick'''
173 self
.controller
.contacts
.set_nick(nick
)