-
Notifications
You must be signed in to change notification settings - Fork 1
/
exampleScript.py
54 lines (41 loc) · 1.42 KB
/
exampleScript.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
from jabberbot import JabberBot, botcmd
import datetime
import logging
import sys
import time;
from config import username, password, chatroom, adminuser
class SystemInfoJabberBot(JabberBot):
@botcmd
def serverinfo( self, mess, args):
"""Displays information about the server"""
version = open('/proc/version').read().strip()
loadavg = open('/proc/loadavg').read().strip()
return '%snn%s' % ( version, loadavg, )
@botcmd
def time( self, mess, args):
"""Displays current server time"""
return str(datetime.datetime.now())
@botcmd
def rot13( self, mess, args):
"""Returns passed arguments rot13'ed"""
return args.encode('rot13')
@botcmd
def whoami(self, mess, args):
"""Tells you your username"""
return mess.getFrom().getStripped()
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
bot = SystemInfoJabberBot(username,password)
bot.join_room(chatroom, 'credilbot')
bot.send(adminuser, 'Hello Julien, je suis connecte')
#print bot.muc_room_participants(chatroom);
bot.send(chatroom, 'Testing...', None, 'groupchat')
while 1:
bot.send(chatroom, str(datetime.datetime.now()), None, 'groupchat')
time.sleep(5)
bot.serve_forever()