-
Notifications
You must be signed in to change notification settings - Fork 0
/
comandos_economia.py
514 lines (372 loc) · 15.6 KB
/
comandos_economia.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
import asyncio
import discord
from discord.ext import commands
import json
import random
class Economia(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=["carteira", "conta"])
async def dinheiro(self, ctx):
await self.abrir_conta(ctx.author)
user = ctx.author
users = await self.get_banco()
quant_carteira = users[str(user.id)]["carteira"]
quant_cofre = users[str(user.id)]["cofre"]
em = discord.Embed(title=f"💰 Conta do {ctx.author.name}!", color=ctx.author.color)
em.add_field(name="Carteira 🪙", value=quant_carteira)
em.add_field(name="Cofre 🪙", value=quant_cofre)
await ctx.send(embed=em)
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown): # Verifica se está em cooldown
msg = f"**Ainda tá em cooldown**, tente novamente em {error.retry_after:.2f}s"
await ctx.send(msg)
@commands.command(aliases=["implorar"])
@commands.cooldown(5, 60, commands.BucketType.user)
async def pedir(self, ctx):
await self.abrir_conta(ctx.author)
user = ctx.author
users = await self.get_banco()
ganhos = random.randrange(201)
await ctx.send(f"Alguém te deu {ganhos} 🪙!!")
users[str(user.id)]["carteira"] += ganhos
with open("banco.json", "w") as f:
json.dump(users, f)
@commands.command()
async def sacar(self, ctx, quantia=None):
await self.abrir_conta(ctx.author)
if quantia is None:
await ctx.send("📤 Infome a quantia que deseja sacar!")
return
din = await self.atualizar_banco(ctx.author)
quantia = int(quantia)
if quantia > din[1]:
await ctx.send("Você não é rico não!")
return
if quantia < 0:
await ctx.send("Como que tu vai sacar dinheiro negativo?")
return
await self.atualizar_banco(ctx.author, quantia)
await self.atualizar_banco(ctx.author, -1 * quantia, "cofre")
await ctx.send(f"Você sacou {quantia} 🪙!")
@commands.command(aliases=["cofre"])
async def depositar(self, ctx, quantia=None):
await self.abrir_conta(ctx.author)
if quantia is None:
await ctx.send("📥 Infome a quantia que deseja depositar!")
return
din = await self.atualizar_banco(ctx.author)
quantia = int(quantia)
if quantia > din[0]:
await ctx.send("Você não é rico não!")
return
if quantia < 0:
await ctx.send("Como que tu vai depositar dinheiro negativo?")
return
await self.atualizar_banco(ctx.author, -1 * quantia)
await self.atualizar_banco(ctx.author, quantia, "cofre")
await ctx.send(f"Você depositou {quantia} 🪙!")
@commands.command()
async def enviar(self, ctx, member: discord.Member, quantia=None):
await self.abrir_conta(ctx.author)
await self.abrir_conta(member)
if quantia is None:
await ctx.send("💸 Infome a quantia que deseja enviar!")
return
din = await self.atualizar_banco(ctx.author)
if quantia == "all":
quantia = din[0]
quantia = int(quantia)
if quantia > din[1]:
await ctx.send("Você não é rico não!")
return
if quantia < 0:
await ctx.send("Como que tu vai depositar dinheiro negativo?")
return
await self.atualizar_banco(ctx.author, -1 * quantia, "cofre")
await self.atualizar_banco(member, quantia, "cofre")
await ctx.send(f"Você deu {quantia} 🪙!")
@commands.command()
@commands.cooldown(1, 300, commands.BucketType.user)
async def roubar(self, ctx, member: discord.Member):
await self.abrir_conta(ctx.author)
await self.abrir_conta(member)
din = await self.atualizar_banco(member)
if din[0] < 100:
await ctx.send("🔒 Não vale a pena...")
return
ganhos = random.randrange(0, din[0])
await self.atualizar_banco(ctx.author, ganhos)
await self.atualizar_banco(member, -1 * ganhos)
await ctx.send(f"O cara roubou aqui!!! Foram {ganhos} 🪙 do {member.mention}!")
@commands.command(aliases=["gambling", "roletar"])
@commands.cooldown(1, 5, commands.BucketType.user)
async def apostar(self, ctx, quantia=None):
await self.abrir_conta(ctx.author)
if quantia is None:
await ctx.send("🎰 Infome a quantia que deseja apostar!")
return
din = await self.atualizar_banco(ctx.author)
if quantia == "all" or quantia == "tudo":
quantia = din[0]
quantia = int(quantia)
if quantia > din[0]:
await ctx.send("Você não é rico não!")
return
if quantia < 0:
await ctx.send("Como que tu vai apostar dinheiro negativo?")
return
final = []
for _ in range(3):
a = random.choice(["🔔", "🧲", "🧶", "🧸", "7️⃣", "💎", "🍒", "🍀"])
final.append(a)
await ctx.send(str(final))
if final[0] == final[1] and final[1] == final[2]:
await self.atualizar_banco(ctx.author, 5 * quantia)
await ctx.send(f"Você ganhou {5 * quantia} 🪙!!!")
elif final[0] == final[1] or final[0] == final[2] or final[2] == final[1]:
await self.atualizar_banco(ctx.author, 2 * quantia)
await ctx.send(f"Você ganhou {2 * quantia} 🪙!!!")
else:
await self.atualizar_banco(ctx.author, -1 * quantia)
await self.atualizar_banco(self.bot.user, quantia, "cofre")
await ctx.send("Você perdeu...")
async def abrir_conta(self, user):
users = await self.get_banco()
if str(user.id) in users:
return False
else:
users[str(user.id)] = {}
users[str(user.id)]["carteira"] = 0
users[str(user.id)]["cofre"] = 0
users[str(user.id)]["mochila"] = []
with open("banco.json", "w") as f:
json.dump(users, f)
return True
async def get_banco(self):
with open("banco.json", "r") as f:
users = json.load(f)
return users
async def atualizar_banco(self, user, quantia=0, modo="carteira"):
users = await self.get_banco()
quantia = int(quantia)
users[str(user.id)][modo] += quantia
with open("banco.json", "w") as f:
json.dump(users, f)
din = [users[str(user.id)]["carteira"], users[str(user.id)]["cofre"]]
return din
lojinha = [
{"nome": "Waffle", "preco": 100, "emoji": "🧇", "descricao": "comida"},
{"nome": "Castigo 60s", "preco": 25000, "emoji": "😝", "descricao": "utilitario"},
{"nome": "Castigo 5min", "preco": 100000, "emoji": "🤔", "descricao": "utilitario"},
{"nome": "Castigo 10min", "preco": 500000, "emoji": "😭", "descricao": "utilitario"},
{"nome": "Castigo 1h", "preco": 1000000, "emoji": "😱", "descricao": "utilitario"},
{"nome": "Castigo 1 semana", "preco": 100000000, "emoji": "🥵", "descricao": "utilitario"},
{"nome": "Cargo milionário **(Waffle)**", "preco": 1000000, "emoji": "💵", "descricao": "cargo"},
{"nome": "Cargo bilionário **(Waffle)**", "preco": 1000000000, "emoji": "💶", "descricao": "cargo"},
]
@commands.command(aliases=["store", "mercado", "lojinha", "market"])
async def loja(self, ctx):
em = discord.Embed(title="Loja 🛍️", color=0xf2bc66)
em.add_field(name="------------------\nProduto", value=f"Preço 🪙 | Emoji\n**------------------**")
for item in self.lojinha:
nome = item["nome"]
preco = item["preco"]
emoji = item["emoji"]
em.add_field(name=nome, value=f"{preco} | {emoji}", inline=False)
await ctx.send(embed=em)
@commands.command()
async def comprar(self, ctx, item, quantidade=1):
await self.abrir_conta(ctx.author)
res = await self.comprar_isso(ctx.author, item, quantidade)
if not res[0]:
if res[1] == 1:
await ctx.send("Não tem isso ai na vendinha!")
return
if res[1] == 2:
await ctx.send(f"Você não tem dinheiro suficiente na carteira para {quantidade} {item}")
return
await ctx.send(f"Você comprou {quantidade} {item}")
async def comprar_isso(self, user, item_nome, quantidade):
item_nome = item_nome.lower()
nome_ = None
for item in self.lojinha:
nome = item["nome"].lower()
if (nome == item_nome):
nome_ = nome
preco = item["preco"]
break
if (nome_ == None):
return [False, 1]
custo = preco * quantidade
users = await self.get_banco()
din = await self.atualizar_banco(user)
if (din[0] < custo):
return [False, 2]
try:
i = 0
t = None
for coisa in users[str(user.id)]["mochila"]:
n = coisa["item"]
if n == item_nome:
quant_velha = coisa["quantidade"]
nova_quant = quant_velha + quantidade
users[str(user.id)]["mochila"][i]["quantidade"] = nova_quant
t = 1
break
i += 1
if t == None:
obj = {"item":item_nome, "quantidade": quantidade}
users[str(user.id)]["mochila"].append(obj)
except:
obj = {"item":item_nome, "quantidade": quantidade}
users[str(user.id)]["mochila"] = [obj]
with open("banco.json", "w") as f:
json.dump(users, f)
await self.atualizar_banco(user, custo * -1, "carteira")
return [True, "Funcionou"]
@commands.command(aliases=["bag", "itens", "inventario"])
async def mochila(self, ctx):
await self.abrir_conta(ctx.author)
user = ctx.author
users = await self.get_banco()
try:
mochila = users[str(user.id)]["mochila"]
except:
mochila = []
em = discord.Embed(title="🎒 Mochila", color=0xf2bc66)
for item in mochila:
nome = item["item"]
quantidade = item["quantidade"]
em.add_field(name=nome, value=quantidade)
await ctx.send(embed=em)
@commands.command(aliases=["utilizar"])
async def usar(self, ctx, item, quantidade=1, member=None):
await self.abrir_conta(ctx.author)
res = await self.usar_isso(ctx.author, item, quantidade)
if not res[0]:
if res[1] == 1:
await ctx.send("Esse item não existe...")
return
if res[1] == 2:
await ctx.send(f"Você não tem {quantidade} {item} na sua 🎒!")
return
if res[1] == 3:
await ctx.send(f"Você não tem {item} na sua 🎒!")
return
if res[2]["descricao"] == "comida":
await ctx.send(f"Você comeu {quantidade} {item}")
elif res[2]["descricao"] == "utilitario":
await ctx.send(f"Você aplicou {res[2]['nome']} em {member}!")
async def usar_isso(self, user, item_nome, quantidade):
item_nome = item_nome.lower()
item_usar = None
for item in self.lojinha:
nome = item["nome"].lower()
if nome == item_nome:
item_usar = item
break
if item_usar is None:
return [False, 1]
users = await self.get_banco()
try:
i = 0
f = None
for coisa in users[str(user.id)]["mochila"]:
n = coisa["item"]
if n == item_nome:
if item_usar["descricao"] == "utilitario":
quantidade = 1
quant_velha = coisa["quantidade"]
nova_quant = quant_velha - quantidade
if nova_quant < 0:
return [False, 2, item_usar]
users[str(user.id)]["mochila"][i]["quantidade"] = nova_quant
f = 1
break
i += 1
if f is None:
return [False, 3, item_usar]
except:
return [False, 3, item_usar]
with open("banco.json", "w") as f:
json.dump(users, f)
return [True, "Funcionou", item_usar]
@commands.command()
async def vender(self, ctx, item, quantidade=1):
await self.abrir_conta(ctx.author)
res = await self.vender_isso(ctx.author, item, quantidade)
if not res[0]:
if res[1] == 1:
await ctx.send("Esse item não existe...")
return
if res[1] == 2:
await ctx.send(f"Você não tem {quantidade} {item} na sua 🎒!")
return
if res[1] == 3:
await ctx.send(f"Você não tem {item} na sua 🎒!")
return
await ctx.send(f"Você vendeu {quantidade} {item}")
async def vender_isso(self, user, item_nome, quantidade, preco=None):
item_nome = item_nome.lower()
nome_ = None
for item in self.lojinha:
nome = item["nome"].lower()
if nome == item_nome:
nome_ = nome
if preco is None:
preco = 0.8 * item["preco"]
break
if nome_ is None:
return [False, 1]
custo = preco * quantidade
users = await self.get_banco()
din = await self.atualizar_banco(user)
try:
i = 0
f = None
for coisa in users[str(user.id)]["mochila"]:
n = coisa["item"]
if n == item_nome:
quant_velha = coisa["quantidade"]
nova_quant = quant_velha - quantidade
if nova_quant < 0:
return [False, 2]
users[str(user.id)]["mochila"][i]["quantidade"] = nova_quant
f = 1
break
i += 1
if f is None:
return [False, 3]
except:
return [False, 3]
with open("banco.json", "w") as f:
json.dump(users, f)
await self.atualizar_banco(user, custo, "carteira")
return [True, "Funcionou"]
@commands.command(aliases=["rk"])
async def ranking(self, ctx, x=3):
users = await self.get_banco()
ranking = {}
total = []
for user in users:
nome = int(user)
quant_total = users[user]["carteira"] + users[user]["cofre"]
ranking[quant_total] = nome
total.append(quant_total)
total = sorted(total, reverse=True)
em = discord.Embed(title=f"🏆 Top {x} pessoas mais ricas", description="É rankeado através da quantia total de dinheiro do usuário", color=0xf2bc66)
i = 1
for qtd in total:
id_ = ranking[qtd]
membro = self.bot.get_user(id_)
nome = membro.name
em.add_field(name=f"{i}. {nome}", value=f"{qtd}", inline=False)
if i == x:
break
else:
i += 1
await ctx.send(embed=em)
async def setup(bot):
await bot.add_cog(Economia(bot))