-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtalkBot.py
More file actions
executable file
·57 lines (47 loc) · 2.65 KB
/
gtalkBot.py
File metadata and controls
executable file
·57 lines (47 loc) · 2.65 KB
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
import sys
import time
import panic
from PyGtalkRobot import GtalkRobot
#########################################################################################
chatBot = panic.panicBot()
class SampleBot(GtalkRobot):
#Regular Expression Pattern Tips:
# I or IGNORECASE <=> (?i) case insensitive matching
# L or LOCALE <=> (?L) make \w, \W, \b, \B dependent on the current locale
# M or MULTILINE <=> (?m) matches every new line and not only start/end of the whole string
# S or DOTALL <=> (?s) '.' matches ALL chars, including newline
# U or UNICODE <=> (?u) Make \w, \W, \b, and \B dependent on the Unicode character properties database.
# X or VERBOSE <=> (?x) Ignores whitespace outside character sets
#"command_" is the command prefix, "001" is the priviledge num, "setState" is the method name.
#This method is used to change the state and status text of the bot.
def command_001_setState(self, user, message, args):
#the __doc__ of the function is the Regular Expression of this command, if matched, this command method will be called.
#The parameter "args" is a list, which will hold the matched string in parenthesis of Regular Expression.
'''(available|online|on|busy|dnd|away|idle|out|off|xa)( +(.*))?$(?i)'''
show = args[0]
status = args[1]
jid = user.getStripped()
# Verify if the user is the Administrator of this bot
if jid == 'geraintwhite@gmail.com':
print jid, " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid)
self.setState(show, status)
self.replyMessage(user, "State settings changed!")
#This method is used to send email for users.
def command_002_SendEmail(self, user, message, args):
#email ldmiao@gmail.com hello dmeiao, nice to meet you, bla bla ...
'''[email|mail|em|m]\s+(.*?@.+?)\s+(.*?),\s*(.*?)(?i)'''
email_addr = args[0]
subject = args[1]
body = args[2]
#call_send_email_function(email_addr, subject, body)
self.replyMessage(user, "\nEmail sent to "+ email_addr +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.gmtime()))
#This method is used to response users.
def command_100_default(self, user, message, args):
'''.*?(?s)(?m)'''
reply = chatBot.takeInput(message)
self.replyMessage(user, reply)
#########################################################################################
if __name__ == "__main__":
bot = SampleBot()
bot.setState('available', "testing gtalk bot")
bot.start("mail.itsapi@gmail.com", "miranda96")