-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconsole.py
304 lines (253 loc) · 9.8 KB
/
console.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
from logging import log
import src.Logger as logger
from src.WurzelBot import WurzelBot
from src.product.Product import CATEGORY_WATER_PLANTS
import argparse
import i18n
import shlex
# Login data
# You can set them here or pass them as CLI arguments
server = 1
user = ''
pw = ''
lang = 'de' # de, en, bg
portalacc = False
parser = argparse.ArgumentParser()
parser.add_argument('--server', type=int, help='Server number')
parser.add_argument('--user', type=str, help='Username for login')
parser.add_argument('--password', type=str, help='Password for login')
parser.add_argument('--lang', type=str, help="Set Language and Region for the Game and Bot")
parser.add_argument('-p', '--portal', help="If -p or --portal Argument is passed, Portal Account Login will be used.", action='store_true', dest="portalacc")
parser.add_argument('-l', '--log', help="If -l or --log Argument is passed, logging will be enabled.", action='store_true', dest="logging")
args = parser.parse_args()
if args.server != None:
server = args.server
if args.user != None:
user = args.user
if args.password != None:
pw = args.password
if args.lang != None:
lang = args.lang
if args.portalacc != None:
portalacc = args.portalacc
# Global vars
bot: WurzelBot = object
log = False
if args.logging != None:
log = args.logging
i18n.load_path.append('lang')
i18n.set('locale', lang)
i18n.set('fallback', 'en')
def main():
logo()
init()
logging()
while True:
print('')
user_input = input('▶ ').strip()
inputLower = user_input.lower()
if inputLower == 'exit': logout()
elif inputLower.startswith('bee'): bee(user_input)
elif inputLower.startswith('bonsai'): bonsai(user_input)
elif inputLower == 'harvest': harvest()
elif inputLower == '?' or inputLower == 'help': help()
elif inputLower.startswith('buy'): buy(user_input)
elif inputLower == 'games': games()
elif inputLower.startswith('grow-water'): grow_aqua_garden(user_input)
elif inputLower.startswith('grow'): grow(user_input)
elif inputLower.startswith('lowest'): lowest(user_input)
elif inputLower.startswith('stock'): stock(user_input)
elif inputLower == 'user': user_info()
elif inputLower == 'water': water()
elif inputLower == 'weed': remove_weeds()
elif inputLower == 'bonus': getDailyLoginBonus()
elif inputLower == 'wimp': wimp()
elif inputLower.startswith('details'): productDetails(user_input)
else:
print('Unknown command type \'help\' or \'?\' to see all available commands')
def logo():
print(' _ __ _____ __ ')
print(' | | /| / /_ _________ ___ / / _ )___ / /_')
print(' | |/ |/ / // / __/_ // -_) / _ / _ \/ __/')
print(' |__/|__/\_,_/_/ /__/\__/_/____/\___/\__/ ')
print('')
def init():
print(i18n.t('wimpb.initialize_bot'))
if user == '' or pw == '' or portalacc == '':
print(i18n.t('wimpb.login_credentials_not_configured'))
print('')
exit()
global bot
bot = WurzelBot()
succ = bot.login(server, user, pw, lang, portalacc)
if succ != True:
exit(-1)
def logout():
print(i18n.t('wimpb.close_connection'))
print('')
bot.logout()
exit()
def help():
print('Available commands:')
print('-------------------')
print('bee Send bees')
print(' Opt. argument: "2h" (default), "8h", "24h"')
print('bonsai Cut all branches and renew bonsais')
print(' Opt. argument: 2 (default level) - 10')
print('bonus Get the daily login bonus')
print('details Show details to the products')
print(' Opt. argument: "all", "water"')
print('buy Buy a given plant')
print('exit Close connection and exit bot')
print('games Play the minigames')
print('grow Grow a given plant')
print('grow-water Grow a given water plant')
print('harvest Harvest all gardens')
print('help Show all available commands')
print('lowest Show the plant with the lowest stock (unequal zero)')
print(' Opt. argument: "single", "water"')
print('stock Show all plants in stock')
print(' Opt. argument: "sort", "water"')
print('user Show details to the current user')
print('water Water all plants')
print('weed Remove all weed')
print('wimp Process Wimp Customers in Gardens')
def harvest():
print('Harvest all gardens...')
bot.harvest()
def bee(arg_str : str):
arg_str = arg_str.replace('bee', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 1 or (len(args) == 1 and args[0] not in ['2h', '8h', '24h'] and args[0] != ''):
print('Cannot parse input.')
print('Expected format: bee [2h|8h|24h]')
return
tour = 1
if len(args) == 0:
args.append('2h')
tour = 1
elif args[0] == '2h':
tour = 1
elif args[0] == '8h':
tour = 2
elif args[0] == '24h':
tour = 3
print(f'Sending bees for {args[0]}...')
bot.send_bees(tour)
def bonsai(arg_str : str):
arg_str = arg_str.replace('bonsai', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 1 or (len(args) == 1 and args[0] not in ['2', '3', '4', '5', '6', '7', '8', '9', '10'] and args[0] != ''):
print('Cannot parse input.')
print('Expected format: bonsai [2|3|4|...|10]')
return
finish_level = 2
if len(args) == 0:
finish_level = 2
else:
finish_level = int(args[0])
print(f'Cutting bonsais...')
bot.cut_and_renew_bonsais(finish_level)
def buy(arg_str : str):
arg_str = arg_str.replace('buy', '', 1).strip()
args = shlex.split(arg_str)
if len(args) != 2 or (len(args) == 2 and not args[1].isnumeric()):
print('Cannot parse input.')
print('Expected format: buy [plant name] [amount]')
return
print('Buying ' + args[1] + ' ' + args[0] + '...')
bot.shop.buy(args[0], int(args[1]))
def games():
print('Playing minigames...')
bot.minigames.play()
def grow(arg_str : str):
arg_str = arg_str.replace('grow', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 2 or len(args) < 1 or args[0] == '' or (len(args) == 2 and not args[1].isnumeric()):
print('Cannot parse input.')
print('Expected format: grow [plant name] [opt. amount]')
return
if len(args) == 1:
print('Grow ' + args[0] + '...')
bot.growVegetablesInGardens(args[0])
if len(args) == 2:
print('Grow ' + args[1] + ' ' + args[0] + '...')
bot.growVegetablesInGardens(args[0], int(args[1]))
def grow_aqua_garden(arg_str : str):
arg_str = arg_str.replace('grow-water', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 2 or len(args) < 1 or args[0] == '' or (len(args) == 2 and not args[1].isnumeric()):
print('Cannot parse input.')
print('Expected format: grow-water [plant name] [opt. amount]')
return
if len(args) == 1:
print('Grow ' + args[0] + '...')
bot.growPlantsInAquaGardens(args[0])
if len(args) == 2:
print('Grow ' + args[1] + ' ' + args[0] + '...')
bot.growPlantsInAquaGardens(args[0], int(args[1]))
def lowest(arg_str : str):
arg_str = arg_str.replace('lowest', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 1 or (len(args) == 1 and args[0] not in ['single', 'water'] and args[0] != ''):
print('Cannot parse input.')
print('Expected format: lowest [single|water]')
return
if len(args) == 0:
print(bot.getLowestVegetableStockEntry())
elif args[0] == 'single':
print(bot.getLowestSingleVegetableStockEntry())
elif args[0] == 'water':
print(bot.getLowestWaterPlantStockEntry())
def stock(arg_str : str):
arg_str = arg_str.replace('stock', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 1 or (len(args) == 1 and args[0] not in ['sort', 'water'] and args[0] != ''):
print('Cannot parse input.')
print('Expected format: stock [sort|water]')
return
if len(args) == 0:
bot.printStock()
elif args[0] == 'water':
bot.printStock(CATEGORY_WATER_PLANTS)
elif args[0] == 'sort':
print(bot.get_ordered_stock_list())
def user_info():
colWidth = 20
print('User:'.ljust(colWidth) + bot.user.get_username())
print('Anzahl der Gärten:'.ljust(colWidth) + str(bot.user.get_number_of_gardens()))
print('Level:'.ljust(colWidth) + str(bot.user.get_level()) + ' (' + bot.user.get_level_name() + ')')
print('Bar:'.ljust(colWidth) + bot.user.get_bar_formatted())
print('Points:'.ljust(colWidth) + f'{bot.user.get_points():,}'.replace(',', '.'))
print('Coins:'.ljust(colWidth) + str(bot.user.get_coins()))
def water():
print('Water all plants in all gardens...')
bot.water()
def productDetails(arg_str : str):
arg_str = arg_str.replace('details', '', 1).strip()
args = shlex.split(arg_str)
if len(args) > 1 or (len(args) == 1 and args[0] not in ['all', 'water'] and args[0] != ''):
print('Cannot parse input.')
print('Expected format: details [all|water]')
return
if len(args) == 0:
bot.printVegetableDetails()
elif args[0] == 'all':
bot.printProductDetails()
elif args[0] == 'water':
bot.printWaterPlantDetails()
def remove_weeds():
print(i18n.t('wimpb.remove_weed_from_all_gardens'))
bot.remove_weeds()
def getDailyLoginBonus():
print('Claiming daily login bonus...')
bot.get_daily_bonuses()
def wimp():
"""Process Wimp Customers in Gardens"""
print(i18n.t('wimpb.process_wimps'))
bot.sell_to_wimps()
def logging():
if log:
logger.logger()
if __name__ == "__main__":
main()