import asyncio
import discord, json
from discord.ext import commands
import pycommands.roles as roles
intents = discord.Intents.all()
client = commands.Bot(
command_prefix = "!",
intents = intents
)
client.remove_command('help')
# Ядро экономики
async def open_account(self, user):
users = await get_bank_data()
if str(user.id) in users:
return False
else:
users[str(user.id)] = {}
users[str(user.id)]["wallet"] = 10
with open('mainbank.json', "w") as f:
json.dump(users,f)
return True
async def get_bank_data():
with open('mainbank.json', "r") as f:
users = json.load(f)
return users
async def update_bank(user,change = 0, mode = "wallet"):
users = await get_bank_data()
users[str(users.id)][mode] += change
with open('mainbank.json', "w") as f:
json.dump(users,f)
bal = [users[str(user.id)]["wallet"]]
return bal
class Collect_Income(commands.Cog):
def __init__(self, client):
self.client = client
# # # # # #
@commands.Cog.listener()
async def on_ready(self):
print(
f"""- Команда collect-income загружена."""
)
@commands.command(aliases = ["тест"])
async def test(self, ctx):
users = await get_bank_data()
user = ctx.author
wallet_amt = users[str(user.id)]["wallet"]
embed = discord.Embed(
title = f"Зарплата для {user.name}:",
colour = 0xFF0000
)
# Барыга
if discord.utils.find(lambda r: r.name == f"{roles.BARIGA_NAME}", ctx.message.guild.roles) in user.roles:
earnings = 150
# await open_account(self, user)
# wallet_amt += earnings
# with open('mainbank.json', "w") as f:
# json.dump(users, f)
embed.add_field(
name =
f"""
**Барыга**:""",
value =
f"""
- Собрано **{earnings}**!"""
)
await ctx.send(embed = embed)
# # # # # #
def setup(client):
client.add_cog(Collect_Income(client))