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

Commit 5d45670

Browse files
author
Benjamin O'Brien
committed
Backend fixing and some command changes
1 parent fd3a80f commit 5d45670

File tree

13 files changed

+178
-331
lines changed

13 files changed

+178
-331
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Rid of the pycache
22
__pycache__/
3+
*.pyc
34

45
# HIDE THE .ENV AAAAAAAAA
56
.env
67

78
# Please dont track the dbs plz :)
89
# being removed soon
9-
users
10-
guilds
10+
db/
1111

12-
# still a wip
13-
prism.db
12+
# No need for vs code stuff
13+
.vscode/
1414

1515
# Developer stuff
1616
.vscode/

assets/database.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Modules
2+
import sqlite3
3+
4+
# Classes
5+
class Users():
6+
7+
def __init__(self):
8+
9+
self.connection = sqlite3.connect("db/users.db")
10+
self.cursor = self.connection.cursor()
11+
12+
class Guilds():
13+
14+
def __init__(self):
15+
16+
self.connection = sqlite3.connect("db/guilds.db")
17+
self.cursor = self.connection.cursor()
18+
19+
# Setup function
20+
def setup():
21+
22+
u = Users()
23+
g = Guilds()
24+
25+
u.cursor.execute("CREATE TABLE users (id int)")
26+
g.cursor.execute("CREATE TABLE guilds (id int)")
27+
28+
u.connection.commit()
29+
g.connection.commit()
30+
31+
u.connection.close()
32+
g.connection.close()

assets/effects.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

assets/functions.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# assets/functions.py
2+
# Just a bunch of helpful functions that DO NOT require the bot instance.
3+
4+
# Modules
5+
from os import name, system
6+
from json import loads, dumps
7+
8+
# Functions
9+
def clear():
10+
11+
if name == "nt":
12+
13+
system("cls")
14+
15+
elif name == "posix":
16+
17+
system("clear")
18+
19+
else:
20+
21+
raise SystemError("This is an unsupported operating system.")
22+
23+
def server_check(bot):
24+
25+
constant = loads(open("db/guilds", "r").read())
26+
27+
data = loads(open("db/guilds", "r").read())
28+
29+
for server in constant:
30+
31+
if not bot.get_guild(int(server)):
32+
33+
data.pop(server)
34+
35+
for server in bot.guilds:
36+
37+
if not str(server.id) in constant:
38+
39+
data[str(server.id)] = Constants.guild_preset
40+
41+
open("db/guilds", "w").write(dumps(data, indent = 4))
42+
43+
data = loads(open("db/users", "r").read())
44+
45+
for user in data:
46+
47+
if "protected" in data[user]["data"]["tags"]:
48+
49+
data[user]["data"]["tags"].remove("protected")
50+
51+
open("db/users", "w").write(dumps(data, indent = 4))

assets/logging.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,53 @@
55
from termcolor import colored
66

77
# Main class
8-
class Logging:
8+
class Logging():
99

10-
"""
10+
"""
1111
12-
Represents the Prism logging system.
13-
This allows you to output errors in a more user-friendly format.
12+
Represents the Prism logging system.
13+
This allows you to output errors in a more user-friendly format.
1414
15-
"""
15+
"""
1616

17-
def error(_, e):
17+
def __init__(self):
1818

19-
"""
19+
self.warnings = 0
20+
self.errors = 0
2021

21-
Prints an error message to the console.
22-
By default, in a red message wrapped in "[ERROR]".
22+
def error(self, e):
2323

24-
"""
24+
"""
2525
26-
return print(colored(f"[ERROR]: {e.split('exception: ')[1]}", "red"))
26+
Prints an error message to the console.
27+
By default, in a red message wrapped in "[ERROR]".
2728
28-
def warn(_, e):
29+
"""
2930

30-
"""
31+
self.errors += 1
3132

32-
Prints an warning message to the console.
33-
By default, in a yellow/orange message wrapped in "[WARN]".
33+
return print(colored(f"[ERROR]: {e.split('exception: ')[1]}", "red"))
3434

35-
"""
35+
def warn(self, e):
3636

37-
return print(colored(f"[WARN]: {e}", "yellow"))
37+
"""
3838
39-
def inform(_, e):
39+
Prints an warning message to the console.
40+
By default, in a yellow/orange message wrapped in "[WARN]".
4041
41-
"""
42+
"""
4243

43-
Prints an informative message to the console.
44-
By default, in a green message wrapped in "[INFO]"
44+
self.warnings += 1
4545

46-
"""
46+
return print(colored(f"[WARN]: {e}", "yellow"))
47+
48+
def inform(self, e):
49+
50+
"""
51+
52+
Prints an informative message to the console.
53+
By default, in a green message wrapped in "[INFO]"
54+
55+
"""
4756

48-
return print(colored(f"[INFO]: {e}", "green"))
57+
return print(colored(f"[INFO]: {e}", "green"))

assets/prism.py

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# Last revision on August 25th, 2020.
55

66
# Modules
7+
from .functions import clear, server_check
8+
9+
10+
11+
712
import discord
813
from random import choice
914

@@ -18,83 +23,52 @@
1823

1924
from Levenshtein.StringMatcher import StringMatcher
2025

21-
# Classes
22-
class BotInstance:
26+
# Bot creation
27+
def Bot():
2328

24-
def create():
29+
global log, bot
2530

26-
global log
27-
28-
global bot
31+
log = Logging() # might as well setup logging too
32+
33+
bot = commands.Bot(
34+
command_prefix = Tools.get_prefix,
35+
case_insensitive = True,
36+
owner_ids = [
37+
633185043774177280,
38+
666839157502378014
39+
]
40+
)
41+
42+
bot.remove_command("help") # we replace it with our own
2943

30-
log = Logging()
31-
32-
bot = commands.Bot(
33-
command_prefix = Tools.get_prefix,
34-
case_insensitive = True,
35-
owner_ids = [
36-
633185043774177280,
37-
666839157502378014
38-
]
39-
)
40-
41-
bot.remove_command("help")
44+
return bot
4245

43-
return bot
44-
46+
# Classes
4547
class Events:
4648

4749
def on_ready():
4850

49-
if name == "nt":
50-
51-
system("cls")
52-
53-
else:
54-
55-
system("clear")
51+
# Nice startup message
52+
clear()
5653

5754
print(f"Logged in as {bot.user}.")
5855

5956
print(f"-------------{'-' * len(str(bot.user))}-")
6057

6158
print()
62-
63-
constant = loads(open("db/guilds", "r").read())
64-
65-
data = loads(open("db/guilds", "r").read())
66-
67-
for server in constant:
68-
69-
if not bot.get_guild(int(server)):
70-
71-
data.pop(server)
72-
73-
for server in bot.guilds:
74-
75-
if not str(server.id) in constant:
76-
77-
data[str(server.id)] = Constants.guild_preset
78-
79-
open("db/guilds", "w").write(dumps(data, indent = 4))
80-
81-
data = loads(open("db/users", "r").read())
82-
83-
for user in data:
84-
85-
if "protected" in data[user]["data"]["tags"]:
86-
87-
data[user]["data"]["tags"].remove("protected")
8859

89-
open("db/users", "w").write(dumps(data, indent = 4))
60+
# Basic server checking
61+
# This insures that a server is registered if it added Prism during a downtime.
62+
server_check(bot)
9063

64+
# Start our 15-minute status changer
9165
try:
9266

9367
return Tools.status_change.start()
9468

9569
except:
9670

97-
pass
71+
return log.warn("Failed to start the status changer, please do this manually.")
9872

9973
async def error_handler(ctx, error):
10074

0 commit comments

Comments
 (0)