me
/
LeekBots
Archived
1
0
Fork 0
Browse Source

Add avatar

master
sheychen290 4 years ago
parent
commit
099ae144c8
  1. 4
      APILeekwars.py
  2. 28
      LeekBots.py

4
APILeekwars.py

@ -160,7 +160,7 @@ class APIFarmer:
def set_avatar(self, avatar, token):
url = self.url + "/set-avatar/"
return self.session.post(url, data={"avatar" : avatar, "token" : token}).json()
return self.session.post(url, data={"token" : token}, files={'avatar': ('avatar', avatar, 'image/png', {'Expires': '0'})}).json()
def set_github(self, github, token):
url = self.url + "/set-github/"
@ -622,7 +622,7 @@ class APITeam:
def set_emblem(self, team_id, emblem, token):
url = self.url + "/set-emblem/"
return self.session.post(url, data={"team_id" : team_id, "emblem" : emblem, "token" : token}).json()
return self.session.post(url, data={"team_id" : team_id, "token" : token}, files={'emblem': ('emblem', emblem, 'image/png', {'Expires': '0'})}).json()
def set_opened(self, opened, token):
url = self.url + "/set-opened/"

28
LeekBots.py

@ -635,6 +635,15 @@ class Pool:
except ValueError as err:
print(format(err))
def teamEmblem(params, options):
try:
leek = Pool.get(Settings(options), Pool.parse(options))[0]
team = leek.farmer.data['team']['id']
owner = Farmers.farmerIn(Settings(options), Team.getCaptains(team))
owner.teamEmblem(team, open(params[0], 'rb'))
except ValueError as err:
print(format(err))
def teamFight(params, options):
try:
random.seed()
@ -696,6 +705,17 @@ class Pool:
except ValueError as err:
print(format(err))
def farmersAvatar(params, options):
try:
for leek in Pool.get(Settings(options), Pool.parse(options)):
try:
leek.farmer.avatar(open(params[0], 'rb'))
leek.farmer.raiseError('OK') #Ugly
except ValueError as err:
print(format(err))
except ValueError as err:
print(format(err))
class Team:
def create(params, options):
@ -812,6 +832,12 @@ class Farmer:
def fight(self, target):
return self.checkRequest(lwapi.garden.start_farmer_fight(target, self.token))
def avatar(self, avatar):
return self.checkRequest(lwapi.farmer.set_avatar(avatar, self.token))
def teamEmblem(self, team, emblem):
return self.checkRequest(lwapi.team.set_emblem(team, emblem, self.token))
def getFirstLeekId(self):
#NOTE: Deprecated
return next(iter(self.leeks))
@ -919,6 +945,8 @@ if __name__ == "__main__":
.addCommand('pool team composition', 'create a composition. a captain must be register', Pool.teamComposition, [{'name': 'composition'}])\
.addCommand('pool team tournament', 'register composition for team tournament. based on first farmer team', Pool.teamTournament, [])\
.addCommand('pool team fight', 'run team fights', Pool.teamFight, [{'name': 'count', 'optional': True, 'type': int, 'min': 1, 'max': 20}])\
.addCommand('pool team emblem', 'set emblem', Pool.teamEmblem, [{'name': 'file'}])\
.addCommand('pool farmers avatar', 'set avatar for each farmer', Pool.farmersAvatar, [{'name': 'file'}])\
.addCommand('pool farmers tournament', 'register each farmer to tournament', Pool.farmersTournament, [])\
.addCommand('pool auto', 'run "fight, fight force, team fight, tournament, team tournament"', Pool.auto, [])\
.addCommand('team create', 'create a team', Team.create, [{'name': 'name'}, {'name': 'owner'}])\