commit d7e0e3eb2c39bfa4ea517b8c2d6006849029234d Author: godot Date: Sun Oct 20 21:11:29 2024 +0200 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/example-bot.py b/example-bot.py new file mode 100644 index 0000000..061c45f --- /dev/null +++ b/example-bot.py @@ -0,0 +1,110 @@ +import discord +from discord.ext import commands +from private.config import token + +import json +import os + +""" +TODO: +- [ ] The whole Ahoj think +- [ ] Case sensitivity in ahoj function +- [ ] Close bot in specific chanel +- [ ] Git ignore and where to store TOKEN +- [ ] Embeds means what? +- [ ] Seznam sprostych slov a reakci na ne +""" + + +#intents = discord.Intents.default() +#intents.message_content = True + +#bot = commands.Bot(command_prefix='$', intents=intents) + + +os.chdir("/home/godot/Documents/scripts/discord-bot.py") +#os.chdir("/opt/disbot") + +intents = discord.Intents.default() +intents.message_content = True + +#client = discord.Client(intents=intents) +bot = commands.Bot(command_prefix='$', intents=intents) + + + +@bot.event +async def on_ready(): + print(f'We have logged in as {bot.user}') + +""" +@bot.event +async def on_message(message): + + # test is bot is not responding to itself + if message.author == bot.user: + return + + # hello reaction + if message.content.startswith('ahoj'): + await message.channel.send('Zdravím miláčkové!') +""" + +@bot.command() +async def balance(ctx): + # test if acount is opend and makes on if not + await open_account(ctx.author) + + user = ctx.author + users = await get_bank_data() + + wallet_amt = users[str(user.id)]["wallet"] + + em = discord.Embed(title = f"{ctx.author.name}'s balance",color = discord.Color.red()) + em.add_field(name = "Wallet balance", value = wallet_amt) + await ctx.send(embed = em) + + +async def open_account(user): + # opens json file to found if user id is present + + users = await get_bank_data() + + # tests presence + if str(user.id) in users: + return False + else: + users[str(user.id)] = {} + users[str(user.id)]["wallet"] = 100 + + # saves a new data in json + with open("mainbank.json", "w") as f: + json.dump(users,f) + return True + + + # opens json stored data +async def get_bank_data(): + with open("mainbank.json", "r") as f: + users = json.load(f) + + return users + + # for testing perpesis only +@bot.command() +async def beg(ctx): + await open_account(ctx.author) + + users = await get_bank_data() + user = ctx.author + + earnings = 10 + + await ctx.send(f"Someone just gave you {earnings} coins") + + users[str(user.id)]["wallet"] += earnings + + with open("mainbank.json", "w") as f: + json.dump(users,f) + +bot.run(token) diff --git a/mainbank.json b/mainbank.json new file mode 100644 index 0000000..87b15a3 --- /dev/null +++ b/mainbank.json @@ -0,0 +1 @@ +{"412092791733354521": {"wallet": 120}, "232593965910720514": {"wallet": 100}} \ No newline at end of file