- Install
xmpppy
module for python. (Manually download it from Downloads Page or tryeasy_install xmpppy
) - Create a script file. (Ex.
lol_echo_bot.py
) - Follow steps below.
Import
xmpp
.
import xmpp
Make connection to PVP.net server.
conn = xmpp.Client("pvp.net")
if not conn.connect(server=("chat.kr.lol.riotgames.com", 5223)):
print "connect failed."
exit()
Auth your account.
if not conn.auth("USER ID", "AIR_" + "USER PASSWORD", "xiff"):
print "auth failed."
exit()
Your LOL account's id goes
"USER ID"
and your password goes"USER PASSWORD"
.
Define and register message handler, request for roster.
roster = None
def message_handler(conn, msg):
user = roster.getName(str(msg.getFrom()))
text = msg.getBody()
print "[%s] %s" % (user, text)
reply = msg.buildReply("[ECHO] %s" % (text))
reply.setType("chat")
conn.send(reply)
conn.RegisterHandler("message", message_handler)
conn.sendInitPresence(requestRoster=1)
roster = conn.getRoster()
Run loop!
while conn.isConnected():
try:
conn.Process(10)
except KeyboardInterrupt:
break
Finished.
Thx