/
yukibot.py
46 lines (43 loc) · 1.58 KB
/
yukibot.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import xmpp
#import os
#import time
sys.path.append("./core")
from bot import bot
#from func import get_local_time
sys.path.append("./addons")
#from weather import weather_informer
#import weather
def main():
print "init..."
yuki = bot()
print "connecting..."
yuki.connect()
print "auth..."
yuki.auth()
#TODO:Это и начальный статус пренести в отдельную функцию start или как-то там
#Устанавливаем функцию-обработчик сообщений
yuki.client.RegisterHandler('message', yuki.process_message)
yuki.client.RegisterDisconnectHandler(yuki.process_disconnect)
yuki.client.RegisterHandler('presence', yuki.process_presence)
yuki.client.sendInitPresence()
#TODO: Создать функцию подключения к конференции
room = "yukibottest@conference.jabber.ru/yuki"
print "Joining " + room
presence = xmpp.Presence(to=room)
#Закомментированная строка нужна для подключения к конференциям с паролем.
#presence.setTag('x',namespace=xmpp.NS_MUC).setTagData('password','helloandwelcome')
yuki.client.send(presence)
#Начальный статус
yuki.set_status(u"available",u"Привет, мир!")
# Main cycle
while yuki.running == True:
yuki.client.Process(1)
print u"Отключаемся..."
yuki.disconnect()
print u"Выходим..."
sys.exit(0)
#начало
main()