No project description provided
Project description
PyDB! A Library Focused Towards Making SQLITE for Discord Bots easier!
Based on aiosqlite!
Features: Economy Database Handler, Levelling Database Handler, Warns Database Handler
Example for Economy Databases!
import disnake
from disnake.ext import commands
from PyDB import EconomyDB
import random
bot = commands.Bot(command_prefix='!', intents=disnake.Intents.all())
db = EconomyDB()
@bot.event
async def on_ready():
await db.init_db()
print('Online')
@bot.command()
async def cf(ctx: commands.Context, amount: int):
user = await db.create_account(ctx.author.id, 500, 1000)
ch = random.choice([1, 2])
if ch == 1:
await ctx.send(f"You won {amount*2}")
return await db.update_account(ctx.author.id, wallet=user.wallet+amount*2)
await ctx.send(f"You lost {amount}")
return await db.update_account(ctx.author.id, wallet=user.wallet-amount)
@bot.command()
async def bal(ctx: commands.Context, member: disnake.Member=None):
member = ctx.author or member
user = await db.create_account(member.id, 500, 1000)
embed = disnake.Embed(description=f"Wallet: {user.wallet} | Bank: {user.bank}")
await ctx.send(embed=embed)
bot.run("token")
Methods
-
create_account(user_id INTEGER, initial_wallet_amount INTEGER, initial_bank_account INTEGER) [
Returns a Named Tuple if User exists or is added to the Database!] -
read_data(user_id INTEGER) [
Returns a Named Tuple with user data] -
update_account(user_id INTEGER, *, wallet_amount INTEGER, bank_amount INTEGER)
Example for Levels Database!
import disnake
from disnake.ext import commands
from PyDB import LevelDB
bot = commands.Bot(command_prefix='!', intents=disnake.Intents.all())
db = LevelDB()
@bot.command()
async def rank(ctx: commands.Context):
user = await db.create_account(ctx.author.id, 5, 1)
embed = disnake.Embed(description=f"Experience: {user.xp} | Level: {user.level}")
await ctx.send(embed=embed)
@bot.listen("on_ready")
async def on_ready():
await db.init_db()
print('Online')
@bot.listen("on_message")
async def on_message(message: disnake.Message):
if message.author.bot: return
user = await db.create_account(message.author.id, 5, )
if user.xp + 5 % 50 == 0:
await db.update_account(message.author.id, xp=user.xp+5, level=user.level+1)
return await message.channel.send(f"{message.author.mention} has levelled up to {user.level+1}")
await db.update_account(message.author.id, xp=user.xp+5, level=user.level)
bot.run("token")
Methods
-
create_account(user_id INTEGER, initial_experience INTEGER, initial_level INTEGER) [
Returns a Named Tuple if User exists or is added to the Database!] -
read_data(user_id INTEGER) [
Returns a Named Tuple with user data] -
update_account(user_id INTEGER, *, experience INTEGER, level INTEGER)
Example for Warns Database!
import disnake
from disnake.ext import commands
from PyDB import WarnDB
bot = commands.Bot(command_prefix="!", intents=disnake.Intents.all())
db = WarnDB()
@bot.listen("on_ready")
async def on_ready():
await db.init_db()
print("online")
@bot.command()
#check for permissions
async def warn(ctx: commands.Context, member: disnake.Member, *,reason: str):
user_data = await db.create_account(ctx.author.id, 0)
embed = disnake.Embed(title=f"Warning #{user_data.warns+1} from {ctx.guild.name}", description=f"Reason: {reason}", color=ctx.author.color).set_thumbnail(url=member.display_avatar.url)
try:
await member.send(embed=embed)
await ctx.send(f"warned! It was **{member}**'s warning number: {user_data.warns+1}")
await db.update_account(ctx.author.id, warnings=user_data.warns+1)
except disnake.Forbidden:
await ctx.send("could not warn that member!")
@bot.command()
async def infractions(ctx: commands.Context, member: disnake.Member=None):
member = ctx.author or member
user_data = await db.create_account(member.id, 0)
embed = disnake.Embed(title=f"Infractions for {ctx.author.name}", description=f"Warnings: {user_data.warns}")
await ctx.send(embed=embed)
bot.run("token")
Methods
-
create_account(user_id INTEGER, initial_warns INTEGER) [
Returns a Named Tuple if User exists or is added to the Database!] -
read_data(user_id INTEGER) [
Returns a Named Tuple with user data] -
update_account(user_id INTEGER, *, warns INTEGER)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyDcDB-0.4.1.tar.gz.
File metadata
- Download URL: PyDcDB-0.4.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
266ed4597949ed70ce1cb1da744026136e2134d666596975ca29a0d61186cea6
|
|
| MD5 |
c51c5dd15e5ad9d8d392287cb40af2c8
|
|
| BLAKE2b-256 |
89bcab52490716dfaac411b6d7c7b1aa6a4b837e61a3969f2c4921c5f69d5dfe
|
File details
Details for the file PyDcDB-0.4.1-py3-none-any.whl.
File metadata
- Download URL: PyDcDB-0.4.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7cac6eb0ec39eab59dd7c2db47963ac9214a90538cb3081c7f43f23aa043732
|
|
| MD5 |
b875c40b7d15f009a209fc00984519cd
|
|
| BLAKE2b-256 |
61a1b0cc488bc4e3ab19bd84f90a75050a1bde64cad2813a7e4bffeb79997c90
|