hello bot

master
Michael Murtaugh 3 years ago
parent cd4b26e766
commit b3fa78e650

@ -0,0 +1,92 @@
# https://python-socketio.readthedocs.io/en/latest/client.html#creating-a-client-instance
# Actually using local (older) docs
import socketio
# sio = socketio.Client()
sio = socketio.Client(logger=True, engineio_logger=True)
@sio.event
def connect():
print('connection established')
@sio.event
def serverWelcome(version, data, startTime):
print('serverWelcome', version, data, startTime)
# sio.emit('my response', {'response': 'my response'})
@sio.event
def errorMessage(msg):
print('errorMessage', msg)
# sio.emit('my response', {'response': 'my response'})
@sio.event
def popup(msg):
print('popup', msg)
# sio.emit('my response', {'response': 'my response'})
@sio.event
def playerLeft(data):
print('playerLeft', data)
# sio.emit('my response', {'response': 'my response'})
@sio.event
def playerJoined(data):
print('playerJoined', data)
# sio.emit('my response', {'response': 'my response'})
if data['id'] == sio.sid:
myPlayerInfo['id'] = data['id']
print ("Received my own playerJoined")
else:
print ("Received another player, let's introduce ourselves", myPlayerInfo)
sio.emit("intro", (data['id'], myPlayerInfo))
talkLabelColor = '#FF0000'
@sio.event
def playerTalked(data):
# sample data: {'id': 'f5dd0c091f494a4bac4ebe1b33b713ab', 'color': '#FF0000', 'message': 'I hear you sister!', 'x': 180, 'y': 174}
if data['id'] != sio.sid:
print ('otherPlayerTalked', data)
# nb: it's better to use sio.sleep instead of the usual time.sleep
# as it lets other messages arive in the meantime
sio.sleep(1)
msg = "I hear you!"
d = { 'message': msg, 'color': talkLabelColor, 'room': myPlayerInfo['room'], 'x': myPlayerInfo['x'], 'y': myPlayerInfo['y'] }
print (f"I say {msg}")
sio.emit("talk", d)
@sio.event
def playerFocused(playerid):
print('playerFocused', playerid)
# sio.emit('my response', {'response': 'my response'})
@sio.event
def playerBlurred(playerid):
print('playerBlurred', playerid)
# sio.emit('my response', {'response': 'my response'})
# onIntro
# playerTalked
# godMsg
# playerMoved
# nameValidation
# playerEmoted
# refresh
@sio.event
def disconnect():
print('disconnected from server')
myPlayerInfo = { 'nickName': "iamabot", 'colors': [11,0,6,4], 'avatar': 9, 'room': "likelikeOutside", 'x': 180, 'y': 174 }
# sio.connect('http://localhost:5000')
sio.connect('http://likelike.glitch.me')
# 42["playerJoined",{"id":"42cd0bbdced74d19bc3b7bb8102c3403","nickName":"","colors":[11,0,6,4],"room":"likelikeOutside","avatar":9,"x":180,"y":174,"lastMessage":0,"admin":false,"spam":0,"lastActivity":1641668085404,"muted":false,"IP":"","floodCount":0,"new":true}]
sio.emit("join", myPlayerInfo)
sio.wait()
Loading…
Cancel
Save