Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit f8d049b

Browse files
author
Benjamin O'Brien
committed
🧰 Prism 1.4 Hotfix 3 🧰
1 parent 7401304 commit f8d049b

File tree

5 files changed

+118
-78
lines changed

5 files changed

+118
-78
lines changed

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ __pycache__/
55
.env
66

77
# Please dont track the dbs plz :)
8+
# being removed soon
89
users
910
guilds
1011

12+
# still a wip
13+
prism.db
14+
1115
# Developer stuff
1216
.vscode/

‎commands/currency/rob.py‎

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Modules
2-
import random
32
import discord
3+
from random import randint
44

55
from json import loads, dumps
6-
76
from discord.ext import commands
7+
88
from assets.prism import Cooldowns, Tools
99

1010
# Main Command Class
@@ -37,98 +37,42 @@ async def rob(self, ctx, user = None):
3737
return await ctx.send(embed = Tools.error("Stop trying to rob me."))
3838

3939
db = loads(open("db/users", "r").read())
40-
40+
4141
if not str(user.id) in db:
42-
42+
4343
return await ctx.send(embed = Tools.error(f"{user.name} doesn't have an account."))
44-
45-
victim = db[str(user.id)]
46-
47-
author = db[str(ctx.author.id)]
48-
49-
if victim["balance"] < 100:
50-
51-
return await ctx.send(embed = Tools.error(f"{user.name} doesn't even have 100 coins."))
52-
53-
elif Tools.has_flag(db, user, "protected"):
54-
55-
return await ctx.send(embed = Tools.error(f"{user.name} has a Bank Lock active."))
5644

57-
if random.randint(1, 3) == 1:
58-
59-
fine = random.randint(75, 310)
60-
61-
author["balance"] -= fine
62-
63-
open("db/users", "w").write(dumps(db, indent = 4))
64-
65-
await ctx.send(embed = Tools.error(f"You got busted and were fined {fine} coins."))
45+
elif db[str(user.id)]["balance"] < 500:
6646

67-
return await Cooldowns.set_cooldown(ctx, "rob", 3600)
68-
69-
number = random.randint(1, 5)
70-
71-
if number == 1:
72-
73-
author["balance"] += victim["balance"]
74-
75-
bal = victim["balance"]
47+
return await ctx.send(embed = Tools.error(f"Bruh, {user.name} is poor."))
7648

77-
victim["balance"] = 0
49+
elif db[str(ctx.author.id)]["balance"] < 300:
7850

79-
embed = discord.Embed(title = f"You just robbed {user.name} for {bal} coins and made them go broke.", color = 0x126bf1)
80-
81-
embed.set_author(name = " | Rob", icon_url = self.bot.user.avatar_url)
82-
83-
embed.set_footer(text = f" | Robbed by {ctx.author}.", icon_url = ctx.author.avatar_url)
84-
85-
elif number in range(2, 4):
86-
87-
author["balance"] += round((victim["balance"] / 3) * 2)
51+
return await ctx.send(embed = Tools.error("You need at least 300 coins to rob someone."))
8852

89-
bal = victim["balance"]
53+
elif randint(0, 1):
9054

91-
victim["balance"] -= round((victim["balance"] / 3) * 2)
92-
93-
embed = discord.Embed(title = f"You just robbed {user.name} for {round((bal / 3) * 2)} coins.", color = 0x126bf1)
94-
95-
embed.set_author(name = " | Rob", icon_url = self.bot.user.avatar_url)
96-
97-
embed.set_footer(text = f" | Robbed by {ctx.author}.", icon_url = ctx.author.avatar_url)
55+
# user wins
56+
earn = randint(250, round(db[str(user.id)]["balance"] / 2))
9857

99-
else:
100-
101-
author["balance"] += round(victim["balance"] / 3)
58+
db[str(user.id)]["balance"] -= earn
10259

103-
bal = victim["balance"]
60+
db[str(ctx.author.id)]["balance"] += earn
10461

105-
victim["balance"] -= round(victim["balance"] / 3)
106-
107-
embed = discord.Embed(title = f"You just robbed {user.name} for {round(bal / 3)} coins.", color = 0x126bf1)
108-
109-
embed.set_author(name = " | Rob", icon_url = self.bot.user.avatar_url)
110-
111-
embed.set_footer(text = f" | Robbed by {ctx.author}.", icon_url = ctx.author.avatar_url)
62+
embed = discord.Embed(title = "Nice :ok_hand:", description = f"You just robbed {user.name} and earned `{earn}` coins.", color = 0x126bf1)
11263

113-
try:
64+
else:
11465

115-
await ctx.send(embed = embed)
116-
117-
except:
66+
# caught
67+
fee = randint(300, round(db[str(ctx.author.id)]["balance"] / 2))
11868

119-
if number == 1:
69+
db[str(ctx.author.id)]["balance"] -= fee
12070

121-
embed = discord.Embed(title = f"You just robbed {user.name} for their whole wallet.", color = 0x126bf1)
122-
123-
else:
71+
embed = discord.Embed(title = "L O L", description = f"You failed miserably at robbing {user.name} and got caught!!!111\nYou paid `{fee}` coins as a fee.", color = 0xFF0000)
12472

125-
embed = discord.Embed(title = f"You just robbed {user.name} for ∞ coins.", color = 0x126bf1)
126-
127-
embed.set_author(name = " | Rob", icon_url = self.bot.user.avatar_url)
128-
129-
embed.set_footer(text = f" | Robbed by {ctx.author}.", icon_url = ctx.author.avatar_url)
73+
embed.set_author(name = " | Rob", icon_url = self.bot.user.avatar_url)
13074

131-
await ctx.send(embed = embed)
75+
embed.set_footer(text = " | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url)
13276

13377
open("db/users", "w").write(dumps(db, indent = 4))
13478

‎commands/music/play.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def play(self, ctx, url: str = None):
3434

3535
except:
3636

37-
return await ctx.send(embed = Tools.error("Missing permission(s) to join you're voice channel."))
37+
return await ctx.send(embed = Tools.error("Missing permission(s) to join your voice channel."))
3838

3939
with youtube_dl.YoutubeDL({}) as ytdl:
4040

‎core/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Imports
2+
from .database import Users, Guilds, setup

‎core/database.py‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Modules
2+
import sqlite3
3+
4+
# Classes
5+
class User():
6+
7+
def __init__(self, resp, user):
8+
self.balance = resp[1]
9+
self.level = resp[2]
10+
self.experience = resp[3]
11+
self.user = user
12+
self.has_acc = True if self.user else False
13+
14+
# SQLite Functions
15+
def sql_identifier(s):
16+
17+
return "\"" + s.replace("\"", "\"\"") + "\""
18+
19+
def get_key(cursor, table, user, key):
20+
21+
cursor.execute(f"SELECT * FROM {table} WHERE id=?", (user.id,))
22+
23+
item = cursor.fetchone()
24+
25+
return User(item if item else None, user)
26+
27+
# Classes
28+
class Users():
29+
30+
def __init__(self):
31+
32+
self.conn = sqlite3.connect("prism.db")
33+
self.cursor = self.conn.cursor()
34+
35+
def get_user(self, user):
36+
37+
return get_key(self.cursor, "users", user)
38+
39+
def setup_user(self, id):
40+
41+
self.cursor.execute("INSERT INTO users VALUES (?,?,?,?)", (id, 250, 1, 0))
42+
43+
def save(self):
44+
45+
self.conn.commit()
46+
47+
self.conn.close()
48+
49+
class Guilds():
50+
51+
def __init__(self):
52+
53+
self.conn = sqlite3.connect("prism.db")
54+
self.cursor = self.conn.cursor()
55+
56+
def get_guild(self, id, key = None):
57+
58+
return get_key(self.cursor, "guilds", id, key)
59+
60+
def setup_guild(self, id):
61+
62+
self.cursor.execute("INSERT INTO guilds VALUES (?,?)", (id, "p!"))
63+
64+
def save(self):
65+
66+
self.conn.commit()
67+
68+
self.conn.close()
69+
70+
# Setup function
71+
def setup():
72+
73+
print("Setting up database..")
74+
75+
db = sqlite3.connect("prism.db")
76+
cur = db.cursor()
77+
78+
print("[db]: Created database file.")
79+
80+
cur.execute("CREATE TABLE users (id bigint, balance int, level int, xp int)")
81+
82+
cur.execute("CREATE TABLE guilds (id bigint, prefix text)")
83+
84+
print("[db]: Tables created.")
85+
86+
db.commit()
87+
88+
db.close()
89+
90+
print("[db]: Database saved.")

0 commit comments

Comments
 (0)