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

Commit 79bfc48

Browse files
author
Benjamin O'Brien
committed
Prism 1.4 Hotfix
1 parent e376548 commit 79bfc48

File tree

7 files changed

+156
-59
lines changed

7 files changed

+156
-59
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Rid of the pycache
2-
__pycache__
2+
__pycache__/
33

44
# HIDE THE .ENV AAAAAAAAA
55
.env

assets/effects.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Modules
2+
from json import loads, dumps
3+
4+
# Master effect class
5+
class Effects(object):
6+
7+
def __init__(self, id):
8+
9+
self.id = str(id)
10+
11+
self.db = loads(open("db/users", "r").read())
12+
self.data = self.db[self.id]["data"]
13+
14+
self.effects = self.data["effects"]
15+
16+
self.refresh_data()
17+
18+
def __len__(self):
19+
20+
return len(self.effects)
21+
22+
def refresh_data(self):
23+
24+
self.db = loads(open("db/users", "r").read())
25+
26+
self.data = self.db[self.id]["data"]
27+
28+
def dump_data(self):
29+
30+
open("db/users", "w").write(dumps(self.db, indent = 4))
31+
32+
def add_effect(self, name, duration):
33+
34+
refresh_data()
35+
36+
self.data["effects"][name] = duration
37+
38+
dump_data()

assets/prism.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def on_ready():
9898

9999
async def error_handler(ctx, error):
100100

101-
if ctx.guild.id in [264445053596991498]:
101+
if ctx.guild and ctx.guild.id in [264445053596991498]:
102102

103103
return
104104

@@ -149,14 +149,38 @@ async def on_message(message):
149149
if user.bot:
150150

151151
return
152+
153+
elif not message.guild:
154+
155+
command = message.content.lower()
156+
157+
if not command.startswith("p!"):
158+
159+
return
160+
161+
command = command[2:]
162+
163+
if " " in command:
164+
165+
command = command.split(" ")[0]
166+
167+
if not command in ["ping", "help", "uptime", "invite", "stats", "vote", "eval", "load", "reload"]:
168+
169+
return await ctx.send(embed = Tools.error("That command can only be used in a guild."))
170+
171+
return True
152172

153173
try:
154174

155175
prefix = gdb[str(message.guild.id)]["prefix"]
156176

157177
except:
158178

159-
return
179+
gdb[str(message.guild.id)] = Constants.guild_preset
180+
181+
prefix = "p!"
182+
183+
open("db/guilds", "w").write(dumps(gdb, indent = 4))
160184

161185
if message.content in gdb[str(message.guild.id)]["data"]["triggers"]:
162186

@@ -182,7 +206,13 @@ async def on_message(message):
182206

183207
if "levels-enabled" in gdb[str(message.guild.id)]["tags"]:
184208

185-
await ctx.send(f"> Congratulations, {message.author.mention}! You advanced to level {current_level + 1} :tada:\n> (you can disable these by using ``{prefix}settings levels off``)")
209+
try:
210+
211+
await ctx.send(f"> Congratulations, {message.author.mention}! You advanced to level {current_level + 1} :tada:\n> (you can disable these by using ``{prefix}settings levels off``)")
212+
213+
except:
214+
215+
pass
186216

187217
else:
188218

@@ -318,6 +348,10 @@ def message_delete(message):
318348

319349
return
320350

351+
elif not message.guild:
352+
353+
return
354+
321355
db = loads(open("db/guilds", "r").read())
322356

323357
if len(db[str(message.guild.id)]["data"]["deleted_messages"]) == 5:
@@ -359,7 +393,13 @@ def ensure_command(gdb, msg):
359393

360394
def get_prefix(bot, msg):
361395

362-
return loads(open("db/guilds", "r").read())[str(msg.guild.id)]["prefix"]
396+
db = loads(open("db/guilds", "r").read())
397+
398+
if not msg.guild:
399+
400+
return "p!"
401+
402+
return db[str(msg.guild.id)]["prefix"]
363403

364404
def uppercase(text):
365405

@@ -514,7 +554,8 @@ class Constants:
514554
"commands": {
515555
"sent": 0,
516556
"used": {}
517-
}
557+
},
558+
"effects": {}
518559
}
519560
}
520561

commands/currency/work.py

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Modules
22
import discord
3-
from json import loads, dumps
3+
from random import randint
44

5+
from json import loads, dumps
56
from discord.ext import commands
6-
from random import randint, choice
77

88
from assets.prism import Tools, Constants, Cooldowns
99

@@ -12,48 +12,23 @@ class Work(commands.Cog):
1212

1313
def __init__(self, bot):
1414
self.bot = bot
15-
self.desc = "Work for some hard, cold cash"
15+
self.desc = "Work for some coins"
1616
self.usage = "work"
1717

18-
self.problems = [
19-
{
20-
"equation": "5 + 5",
21-
"answer": "10"
22-
},
23-
{
24-
"equation": "16 + 5",
25-
"answer": "21"
26-
},
27-
{
28-
"equation": "9 + 10",
29-
"answer": "19"
30-
},
31-
{
32-
"equation": "(5 + 5) / 2",
33-
"answer": "5"
34-
},
35-
{
36-
"equation": "5x - 5 = 10; what is x?",
37-
"answer": "3"
38-
},
39-
{
40-
"equation": "((9 x 9) - 1 + 20) / 100",
41-
"answer": "1"
42-
}
43-
]
44-
4518
@commands.command()
4619
async def work(self, ctx):
4720

4821
if Cooldowns.on_cooldown(ctx, "work"):
4922

5023
return await ctx.send(embed = Cooldowns.cooldown_text(ctx, "work"))
51-
52-
failed_earn = randint(20, 80)
53-
54-
problem = choice(self.problems)
5524

56-
bot_msg = await ctx.send(f"You are now working; solve the equation: `{problem['equation']}`.")
25+
n1 = randint(1, 100)
26+
27+
n2 = randint(1, 100)
28+
29+
answer = n1 + n2
30+
31+
bot_msg = await ctx.send(f"You are now working; solve the equation: `{n1} + {n2}`.")
5732

5833
db = loads(open("db/users", "r").read())
5934

@@ -66,12 +41,14 @@ def check(m):
6641
message = await self.bot.wait_for("message", check = check, timeout = 5)
6742

6843
except:
69-
70-
db[str(ctx.author.id)]["balance"] += failed_earn
44+
45+
earnings = randint(20, 100)
46+
47+
db[str(ctx.author.id)]["balance"] += earnings
7148

7249
open("db/users", "w").write(dumps(db, indent = 4))
7350

74-
return await ctx.send(embed = Tools.error(f"You didn't respond fast enough; but you still earned {failed_earn} coins."))
51+
return await ctx.send(embed = Tools.error(f"You didn't respond fast enough; but you still earned {earnings} coins."))
7552

7653
try:
7754

@@ -81,23 +58,25 @@ def check(m):
8158

8259
pass
8360

84-
if not message.content.lower() == problem["answer"]:
61+
if not message.content.lower() == str(answer):
8562

86-
db[str(ctx.author.id)]["balance"] += failed_earn
63+
earnings = randint(20, 100)
64+
65+
db[str(ctx.author.id)]["balance"] += earnings
8766

8867
open("db/users", "w").write(dumps(db, indent = 4))
8968

90-
await ctx.send(embed = Tools.error(f"You messed up at work; but you still earned {failed_earn} coins."))
69+
await ctx.send(embed = Tools.error(f"You messed up at work; but you still earned {earnings} coins."))
9170

9271
return await Cooldowns.set_cooldown(ctx, "work", 600)
9372

94-
good_earnings = randint(200, 450)
73+
reward = randint(200, 450)
9574

96-
db[str(ctx.author.id)]["balance"] += good_earnings
75+
db[str(ctx.author.id)]["balance"] += reward
9776

9877
open("db/users", "w").write(dumps(db, indent = 4))
9978

100-
embed = discord.Embed(title = f"Good job, you went to work and earned {good_earnings} coins.", color = 0x126bf1)
79+
embed = discord.Embed(title = f"Good job, you went to work and earned {reward} coins.", color = 0x126bf1)
10180

10281
embed.set_author(name = " | Work", icon_url = self.bot.user.avatar_url)
10382

commands/entertainment/effects.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Modules
2+
from assets.prism import Tools
3+
from discord.ext import commands
4+
from assets.effects import Effects as Eff
5+
6+
# Main Command Class
7+
class Effects(commands.Cog):
8+
9+
def __init__(self, bot):
10+
self.bot = bot
11+
self.desc = "Checks out your effects"
12+
self.usage = "effects"
13+
14+
@commands.command()
15+
async def effects(self, ctx):
16+
17+
effects = Eff(ctx.author.id)
18+
19+
if not len(effects):
20+
21+
return await ctx.send(embed = Tools.error("You don't have any effects."))
22+
23+
return await ctx.send(str(effects))
24+
25+
# Link to bot
26+
def setup(bot):
27+
bot.add_cog(Effects(bot))

commands/misc/help.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,16 @@ async def embed(self, ctx, cat, prefix, commandClass = None):
9090

9191
@commands.command(aliases = ["info", "commands", "cmds"])
9292
async def help(self, ctx, *, category = None):
93-
94-
db = loads(open("db/guilds", "r").read())
9593

96-
prefix = db[str(ctx.guild.id)]["prefix"]
94+
if ctx.guild:
95+
96+
db = loads(open("db/guilds", "r").read())
97+
98+
prefix = db[str(ctx.guild.id)]["prefix"]
99+
100+
else:
101+
102+
prefix = "p!"
97103

98104
if not category:
99105

commands/misc/vote.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Modules
2-
import json
32
import discord
4-
53
import requests
4+
5+
from json import loads
66
from asyncio import sleep
77

88
from discord.ext import commands
9-
from assets.prism import Cooldowns
9+
from assets.prism import Cooldowns, Tools
1010

1111
# Main Command Class
1212
class Vote(commands.Cog):
@@ -25,7 +25,7 @@ async def vote(self, ctx):
2525

2626
return await ctx.send(embed = Cooldowns.cooldown_text(ctx, "vote"))
2727

28-
bot_data = json.loads(requests.get("https://top.gg/api/bots/685550504276787200", headers = {"Authorization": self.token}).text)
28+
bot_data = loads(requests.get("https://top.gg/api/bots/685550504276787200", headers = {"Authorization": self.token}).text)
2929

3030
base_upvotes = bot_data["points"]
3131

@@ -51,13 +51,13 @@ def check(m):
5151

5252
while failed_attempts < 16:
5353

54-
bot_data = json.loads(requests.get("https://top.gg/api/bots/685550504276787200", headers = {"Authorization": self.token}).text)
54+
bot_data = loads(requests.get("https://top.gg/api/bots/685550504276787200", headers = {"Authorization": self.token}).text)
5555

5656
current_upvotes = bot_data["points"]
5757

5858
if current_upvotes > base_upvotes:
5959

60-
db = json.loads(open("db/users", "r").read())
60+
db = loads(open("db/users", "r").read())
6161

6262
db[str(ctx.author.id)]["balance"] = db[str(ctx.author.id)]["balance"] + 2750
6363

@@ -85,6 +85,12 @@ def check(m):
8585

8686
pass
8787

88+
if Tools.has_flag(db, ctx.author, "premium"):
89+
90+
await Cooldowns.set_cooldown(ctx, "vote", 86400)
91+
92+
break
93+
8894
await Cooldowns.set_cooldown(ctx, "vote", 43200)
8995

9096
break

0 commit comments

Comments
 (0)