-
Notifications
You must be signed in to change notification settings - Fork 1
/
withdraw.py
39 lines (29 loc) · 1.03 KB
/
withdraw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from resources_dict import resources_dict
resource_name_to_id = {}
for id, name in resources_dict.items():
resource_name_to_id[name] = id
class Resource:
def __init__(self, name, quantity=0):
self.name = name
if resource_name_to_id[name] <= 9:
self.id = '0' + str(resource_name_to_id[name])
else:
self.id = str(resource_name_to_id[name])
self.quantity = quantity
def parse_message(lines):
resources = []
for line in lines:
q, name = line.lstrip(' ').split(' x ')
resources.append(Resource(name.lower(), q))
return resources
def withdraw(resources):
command = '/g_withdraw'
if len(resources) <= 8:
for resource in resources:
command += f" {resource.id} {resource.quantity}"
return [command]
else:
return withdraw(resources[:8]) + withdraw(resources[8:])
def missing_to_withdraw(message):
parsed = parse_message(filter(lambda line: line.startswith(' '), message.splitlines()))
return withdraw(parsed)