usr bin env python coding utf-8 import time import xmpp import re impo

 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import xmpp
import re
import random
import config
class Bot(object):
def __init__(self, jid, password, nick):
self.jid = xmpp.protocol.JID(jid)
self.password = password
self.nick = nick
# ['nodebuilder', 'dispatcher', 'gen_auth', 'SASL_auth', 'bind',
# 'socket', 'CONNECTproxy', 'TLS', 'roster', 'browser', 'ibb']
debug_list = ['always', 'nodebuilder']
self.client = xmpp.Client(self.jid.getDomain(), debug=debug_list)
def login(self):
self.client.connect()
self.client.auth(self.jid.getNode(), self.password)
def say_room(self, room_jid, msg):
jid = xmpp.protocol.JID(room_jid)
to = '%s/%s' % (jid.getStripped(), self.nick)
self.client.send(xmpp.Presence(to))
msg = xmpp.Message(to=jid, frm=self.jid, typ='groupchat', body=msg)
self.client.send(msg)
bot = Bot(jid=config.JID, password=config.PASSWORD, nick=config.NICK)
bot.login()
bot.say_room('pytest@conference.jabber.ru', 'hello')
time.sleep(5)