Skip to content

Instantly share code, notes, and snippets.

@NitroXenon
Forked from hallazzang/README.md
Last active August 29, 2015 14:21
Show Gist options
  • Save NitroXenon/7f926b8106bad244dbfd to your computer and use it in GitHub Desktop.
Save NitroXenon/7f926b8106bad244dbfd to your computer and use it in GitHub Desktop.

How to make LOL(League of Legends) chat bot

  1. Install xmpppy module for python. (Manually download it from Downloads Page or try easy_install xmpppy)
  2. Create a script file. (Ex. lol_echo_bot.py)
  3. 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.

import xmpp
conn = xmpp.Client("pvp.net")
if not conn.connect(server=("chat.kr.lol.riotgames.com", 5223)):
print "connect failed."
exit()
if not conn.auth("USER ID", "AIR_" + "USER PASSWORD", "xiff"):
print "auth failed."
exit()
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()
while conn.isConnected():
try:
conn.Process(10)
except KeyboardInterrupt:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment