This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path.example.py
195 lines (163 loc) · 5.9 KB
/
.example.py
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# coding: utf-8
# This file is a part of VK4XMPP Transport
# © simpleApps, 2014.
# This plugin contain all vk4xmpp plugin's API features
# Rename it to "example.py" if you wanna test it
# Please notice that plugins are working in globals() so variable and function names must be unique
## Events (not finished yet so not sorted):
# 01 - transport's start (threaded), no args
# 02 - transport's shutdown (linear)
# 03 - user deletion (linear), args: User object
# 04 - captcha (linear), args: VK object
# 05 - user became online (threaded), args: User object
# 06 - user became offline (linear), args: VK object (don't ask me why, i have no idea)
# 07 - user is logging in (linear, before the friends list wes received), args: User object
# 08 - new user registered, args: user's jid
# 09 - user unregistered, args: user's jid
## Messages: 01 outgoing (vk->xmpp), 02 incoming (xmpp), 03 is used to modify message (xmpp)
## Presences: 01 incoming presence, 02 - is used to modify outgoing presence (xmpp)
def evt01_handler():
"""
Threaded handler.
Called when the transport's loaded and users initialized
But before the modules are being loaded
"""
print "WOW! That's my awesome plugin event!"
registerHandler("evt01", evt01_handler)
def evt02_handler():
"""
Linear handler.
Called when transport's shutting down
"""
print "NOOOOOOOOO! Transport is so awesome, why are you stopping it?"
registerHandler("evt02", evt02_handler)
def evt03_handler(user):
"""
Linear handler.
Called when user has removed his registration ("unsubscribe" presence or "delete" in disco)
Parameters:
user: User class object
Look at the User class for advanced information
"""
print "Print user %s is going to remove us" % (user.source)
registerHandler("evt03", evt03_handler)
def evt04_handler(vk):
"""
Linear handler.
Called when user received a captcha
Parameters:
vk: VK class object
"""
print "Look at this man, he's got a captcha: %s. This image: %s is not for robots" % (vk.source, vk.engine.captcha["img"])
registerHandler("evt04", evt04_handler)
def evt05_handler(user):
"""
Threaded handler.
Called when user became online (our xmpp user, so we received available/probe presence)
Exactly at end of the user.initialize() function
Parameters:
user: User class object
"""
print "Hey, look who came to see us: %s" % user.source
registerHandler("evt05", evt05_handler)
def evt06_handler(vk):
"""
Threaded handler.
Called when user is disconnected (vk)
Exactly when user.vk.disconnect() is called
Parameters:
vk: VK class object
"""
print "We've lost this guy: %s" % vk.source ## yes VK class object too have source attribute
registerHandler("evt06", evt06_handler)
def evt08_handler(source):
"""
Linear handler
Called when a new user registered
"""
registerHandler("evt08", watch_registered)
def evt09_handler(source):
"""
Linear handler
Called when a user has unregistered
"""
registerHandler("evt09", watch_unregistered)
def evt07_handler(user):
"""
Linear handler
Called when user is connecting (if authenticated)
Parameters:
user: User class object
"""
print "User", user.source, "is authenticated!"
def msg01_handler(user, message):
"""
Linear handler.
Called for each message has been received from VK
Parameters:
user: User class object
message: single message json object
Returns:
A tuple of (status, body) where status indicates what to do with the body.
List of statuses:
* MSG_SKIP: message will be skipped and execution of other handlers stopped
* MSG_APPEND: message body will be appended with returning body
* MSG_APPEND: message body will be prepended with returning body
"""
return (MSG_APPEND, "\nmsg01_handler is awesome")
registerHandler("msg01", msg01_handler)
def msg02_handler(msg):
"""
Linear handler.
Called for each message has been received from xmpp
Parameters:
msg: xmpp.Message object
"""
print "Look who's trying to send us a message: %s" % msg.getFrom().getStripped()
registerHandler("msg02", msg02_handler)
def msg03_handler(msg, destination, source):
"""
Linear handler.
Called when transport sending a message to XMPP
Could be used for modifying message before it being sent
Parameters:
msg: xmpp.Message object
destination: message destination
source: message source
Look at sendMessage() in transport's core for advanced information
"""
msg.setTag("awesome", namespace="urn:xmpp:awesome")
registerHandler("msg03", msg03_handler)
def prs01_handler(source, prs):
"""
Trheaded handler. I have no idea why.
Called when presence received (no matter which one, when user in Transport)
Also called when user is just initialized (only after "probe" presence)
Parameters:
source: presence source
prs: xmpp.Presence object
"""
print "Hey, user %s is became %s in xmpp!" % (source, prs.getType())
registerHandler("prs01", prs01_handler)
def prs02_handler(prs, destination, source):
"""
Linear handler.
Same as msg02_handler, but this one is for presence
Parameters:
prs: xmpp.Presence object
destination: message destination
source: message source
Look at sendPresence() in transport's core for advanced information
"""
prs.setTag("c", {"node": "http://psi-dev.googlecode.com/caps", "ver": "0.16"}, xmpp.NS_CAPS)
registerHandler("prs02", prs02_handler)
## AdHoc. To add adhoc option (now only for user settings and only boolean values supported)
## You need to add form field to GLOBAL_USER_SETTINGS
## Example: GLOBAL_USER_SETTINGS["setting_name"] = {"label": "field label", "value": "default-value", "type": "field-type"}
## For field types look http://xmpp.org/extensions/xep-0004.html section 3.3 "Field Types"
## Ok now, look here.
GLOBAL_USER_SETTINGS["awesome_setting"] = {"label": "My new setting", "value": 0} ## If not type added, then boolean will be used
## Settings are being automatically saved as soon as they changed.
## To check if the value is equal to something, do:
## print user.settings.awesome_setting == 0
## where "user" is the User class object