Skip to content

Commit d14ea7f

Browse files
committed
Cleaning file structure
1 parent c52d0ef commit d14ea7f

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

data.py

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

index.py

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,17 @@
11
import os
2-
import discord
32

4-
from discord.ext.commands import DefaultHelpCommand
5-
from data import Bot
6-
from utils import permissions, default
3+
from utils import default
4+
from utils.data import Bot, HelpFormat
75

86
config = default.get("config.json")
9-
10-
11-
class HelpFormat(DefaultHelpCommand):
12-
def get_destination(self, no_pm: bool = False):
13-
if no_pm:
14-
return self.context.channel
15-
else:
16-
return self.context.author
17-
18-
async def send_error_message(self, error):
19-
destination = self.get_destination(no_pm=True)
20-
await destination.send(error)
21-
22-
async def send_command_help(self, command):
23-
self.add_command_formatting(command)
24-
self.paginator.close_page()
25-
await self.send_pages(no_pm=True)
26-
27-
async def send_pages(self, no_pm: bool = False):
28-
try:
29-
if permissions.can_react(self.context):
30-
await self.context.message.add_reaction(chr(0x2709))
31-
except discord.Forbidden:
32-
pass
33-
34-
try:
35-
destination = self.get_destination(no_pm=no_pm)
36-
for page in self.paginator.pages:
37-
await destination.send(page)
38-
except discord.Forbidden:
39-
destination = self.get_destination(no_pm=True)
40-
await destination.send("Couldn't send help to you due to blocked DMs...")
41-
42-
437
print("Logging in...")
44-
bot = Bot(command_prefix=config.prefix, prefix=config.prefix, command_attrs=dict(hidden=True), help_command=HelpFormat())
8+
9+
bot = Bot(
10+
command_prefix=config.prefix,
11+
prefix=config.prefix,
12+
command_attrs=dict(hidden=True),
13+
help_command=HelpFormat()
14+
)
4515

4616
for file in os.listdir("cogs"):
4717
if file.endswith(".py"):

utils/data.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import discord
2+
3+
from utils import permissions
4+
from discord.ext.commands import AutoShardedBot, DefaultHelpCommand
5+
6+
7+
class Bot(AutoShardedBot):
8+
def __init__(self, *args, prefix=None, **kwargs):
9+
super().__init__(*args, **kwargs)
10+
11+
async def on_message(self, msg):
12+
if not self.is_ready() or msg.author.bot or not permissions.can_send(msg):
13+
return
14+
15+
await self.process_commands(msg)
16+
17+
18+
class HelpFormat(DefaultHelpCommand):
19+
def get_destination(self, no_pm: bool = False):
20+
if no_pm:
21+
return self.context.channel
22+
else:
23+
return self.context.author
24+
25+
async def send_error_message(self, error):
26+
destination = self.get_destination(no_pm=True)
27+
await destination.send(error)
28+
29+
async def send_command_help(self, command):
30+
self.add_command_formatting(command)
31+
self.paginator.close_page()
32+
await self.send_pages(no_pm=True)
33+
34+
async def send_pages(self, no_pm: bool = False):
35+
try:
36+
if permissions.can_react(self.context):
37+
await self.context.message.add_reaction(chr(0x2709))
38+
except discord.Forbidden:
39+
pass
40+
41+
try:
42+
destination = self.get_destination(no_pm=no_pm)
43+
for page in self.paginator.pages:
44+
await destination.send(page)
45+
except discord.Forbidden:
46+
destination = self.get_destination(no_pm=True)
47+
await destination.send("Couldn't send help to you due to blocked DMs...")

utils/dataIO.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22

33

4-
def change_value(file, value, changeto):
4+
def change_value(file: str, value: str, changeto: str):
55
try:
66
with open(file, "r") as jsonFile:
77
data = json.load(jsonFile)
@@ -13,7 +13,7 @@ def change_value(file, value, changeto):
1313
json.dump(data, jsonFile, indent=2)
1414

1515

16-
def append_value(file, value, addition):
16+
def append_value(file: str, value: str, addition: str):
1717
try:
1818
with open(file, "r") as jsonFile:
1919
data = json.load(jsonFile)

0 commit comments

Comments
 (0)