Skip to content

Instantly share code, notes, and snippets.

@hallazzang
Last active March 25, 2023 02:40
Show Gist options
  • Save hallazzang/8327299 to your computer and use it in GitHub Desktop.
Save hallazzang/8327299 to your computer and use it in GitHub Desktop.
How to make LOL(League of Legends) chat bot (in Python)

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
@xaronnn
Copy link

xaronnn commented Jun 27, 2017

Thx

@hallazzang
Copy link
Author

@xaronnn Of course you can, though I can't write a code for you.

@Swiftzn
Copy link

Swiftzn commented Oct 27, 2017

Would this still work

@hallazzang
Copy link
Author

@Swiftzn Well, I haven't tested it with the new client. Sorry for the late reply, GitHub didn't send me any notification 😢

@HofmanCHFA
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment