Skip to content

Commit 1b463eb

Browse files
authored
Merge pull request #56 from BlueAtomic/rewrite
2 parents 5d5c67f + 7d3cf6f commit 1b463eb

File tree

16 files changed

+302
-297
lines changed

16 files changed

+302
-297
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ config.json
33
.idea
44
.vscode
55
cogs/__pycache__
6-
__pycache__
6+
__pycache__
7+
venv

CONFIGURATION.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuration
22
Pingernos py offers three different ways to configure it, a config file, environment variables and a .env
3-
If you wish to use the config file, you must set the `use_json` variable in [getdata](./utils.py) to `True` and copy the [example.config.json](./example.config.json) to a new file called config.json in the root folder and modify the options in it.
3+
If you wish to use the config file, you must set the `use_json` variable in [getdata](./utilities/data.py) to `True` and copy the [example.config.json](./example.config.json) to a new file called config.json in the root folder and modify the options in it.
44
If you wish to use a .env file, just copy the [example.env](./example.env) to a new file called .env in the root folder and modify the options in it, you can use environment variables and a .env file at the same time if you so desire.
55
Environment variables use `SCREAMING_SNAKE_CASE` while the configuration file uses `PascalCase`.
66

@@ -9,45 +9,45 @@ If a config file is missing, pingernos will try to load the environment variable
99
## Auth Token (required)
1010
Discord bot authentication token, can be generated in the [Developer Portal](https://discord.com/developers/applications/)
1111

12-
| type | config file | environment |
13-
|--------|-------------|---------------------|
14-
| string | `Token` | `TOKEN` |
12+
| type | config file | environment |
13+
|--------|-------------|-------------|
14+
| string | `Token` | `TOKEN` |
1515

1616
## Prefix (required)
1717
Prefix to use for commands, can be a mention or a string
1818

19-
| type | config file | environment |
20-
|--------|-------------|---------------------|
21-
| string | `Prefix` | `PREFIX` |
19+
| type | config file | environment |
20+
|--------|-------------|-------------|
21+
| string | `Prefix` | `PREFIX` |
2222

2323
## Owners (required)
2424
Array of user ids that are allowed to use owner only features
2525

26-
| type | config file | environment |
27-
|----------|--------------------|----------------------------|
28-
| string[] | `Owners` | `OWNERS` |
26+
| type | config file | environment |
27+
|----------|-------------|-------------|
28+
| string[] | `Owners` | `OWNERS` |
2929

3030
## FeatureGuilds (required)
3131
Array of guild ids that are allowed to use owner only features
3232

33-
| type | config file | environment |
34-
|----------|--------------------|----------------------------|
35-
| string[] | `FeatureGuilds` | `FEATURE_GUILDS` |
33+
| type | config file | environment |
34+
|----------|------------------|------------------|
35+
| string[] | `FeatureGuilds` | `FEATURE_GUILDS` |
3636

3737
## Logs (required)
3838

3939
### JoinWebhook (required)
4040
Webhook to send join logs to
4141

42-
| type | config file | environment |
43-
|--------|-----------------|------------------------|
42+
| type | config file | environment |
43+
|--------|--------------------|--------------------|
4444
| string | `Logs.JoinWebhook` | `LOGS_JOINWEBHOOK` |
4545

4646
### LeaveWebhook (required)
4747
Webhook to send leave logs to
4848

49-
| type | config file | environment |
50-
|--------|-----------------|------------------------|
49+
| type | config file | environment |
50+
|--------|---------------------|---------------------|
5151
| string | `Logs.LeaveWebhook` | `LOGS_LEAVEWEBHOOK` |
5252

5353
## Database (required)
@@ -56,34 +56,34 @@ MySQL/MariaDB access credentials. Other SQL dialects or Databases are not suppor
5656
### Host
5757
Database hostname or IP
5858

59-
| type | config file | environment |
60-
|--------|-----------------|------------------------|
61-
| string | `Database.Host` | `DB_HOST` |
59+
| type | config file | environment |
60+
|--------|-----------------|-------------|
61+
| string | `Database.Host` | `DB_HOST` |
6262

6363
### User
6464
Database username
6565

66-
| type | config file | environment |
67-
|--------|-----------------|------------------------|
68-
| string | `Database.User` | `DB_USER` |
66+
| type | config file | environment |
67+
|--------|-----------------|-------------|
68+
| string | `Database.User` | `DB_USER` |
6969

7070
### Password
7171
Database password
7272

73-
| type | config file | environment |
74-
|--------|---------------------|----------------------------|
73+
| type | config file | environment |
74+
|--------|---------------------|---------------|
7575
| string | `Database.Password` | `DB_PASSWORD` |
7676

7777
### Database
7878
Database name
7979

80-
| type | config file | environment |
81-
|--------|---------------------|----------------------------|
80+
| type | config file | environment |
81+
|--------|---------------------|---------------|
8282
| string | `Database.Database` | `DB_DATABASE` |
8383

8484
### Port
8585
Database port
8686

87-
| type | config file | environment |
88-
|--------|-----------------|------------------------|
89-
| int | `Database.Port` | `DB_PORT` |
87+
| type | config file | environment |
88+
|--------|-----------------|-------------|
89+
| int | `Database.Port` | `DB_PORT` |

SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
We only support the following versions with security updates:
66

7-
*This'll usually be limited to the latest version.*
7+
*This will usually be limited to the latest version.*
88

99
| Version | Supported |
10-
| ------- | ------------------ |
10+
|---------|--------------------|
1111
| 2.3.x | :white_check_mark: |
1212
| < 2.0 | :x: |
1313

@@ -22,7 +22,7 @@ Amongst other things, things that counts as a security vulnerability include, bu
2222

2323
### How to report it
2424
We ask you to report any and all vulnerabilities to us in one of the following ways:
25-
- Sending a mail to [stormsnuitje@gmail.com](mailto:stormsnuitje@gmail.com)
25+
- Sending a mail to [joshuaslui0203@gmail.com](mailto:joshuaslui0203@gmail.com)
2626
- Creating a [security advisory](https://github.com/BlueAtomic/pingernos/security/advisories/new)
2727

2828
... ***Do not report security vulnerabilities in discord, this is highly unsafe and will have consequences on your stay there.***

cogs/blacklist.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from discord import slash_command, option
33
from discord.ext import commands
44
from discord.ext.bridge import Bot
5-
from utils import Utils
5+
from utilities.database import modifier
66

77

88
class Blacklist(commands.Cog):
@@ -15,13 +15,7 @@ def __init__(self, bot: Bot):
1515
@option("reason", str, description="The reason for the blacklist")
1616
async def blacklist(self, ctx, server, reason):
1717
""" Blacklist a server from the bot """
18-
cursor = await Utils.mysql_login()
19-
database = cursor.cursor()
20-
database.execute("INSERT IGNORE INTO blacklist (guild_id, reason) VALUES (%s, %s)", (server.id, reason))
21-
cursor.commit()
22-
database.close()
23-
cursor.close()
24-
18+
await modifier("INSERT IGNORE INTO blacklist (guild_id, reason) VALUES (%s, %s)", [server.id, reason])
2519
guild = self.bot.get_guild(server.id)
2620
await guild.leave()
2721
return await ctx.respond(f'Successfully added guild {server} to the blacklist for:\n**{reason}**')

cogs/checkip.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
1-
from discord.ext import commands, bridge
2-
from discord import Embed
3-
from mcstatus import JavaServer
4-
from discord.ext.bridge import Bot
5-
from discord.ext.bridge.context import BridgeContext
6-
from utils import Utils
1+
from asyncio import wait_for
2+
from discord import slash_command, option, Embed
3+
from discord.ext import commands
4+
from discord.ext.commands import Bot
5+
from utilities.data import Colors, get_server_status
6+
from utilities.utility import check_ip
7+
78

89
class CheckIP(commands.Cog):
910
def __init__(self, bot: Bot):
1011
self.bot = bot
1112

12-
@bridge.bridge_command(aliases=["checkserverip", "check"], description="Checks if an Aternos-IP is free to use.")
13-
async def checkip(self, ctx: BridgeContext, address=None):
14-
if address is None:
15-
return await Utils.respond(ctx, "Please provide a Aternos server ip!\nExample: example.aternos.me")
16-
if not address.endswith(".aternos.me"):
17-
address += ".aternos.me"
18-
if address.count(".") > 2:
19-
return await Utils.respond(ctx, "Please provide a valid Aternos server ip!\nExample: example.aternos.me")
13+
@slash_command(aliases=["checkserverip", "check"], description="Checks if an Aternos-IP is free to use.")
14+
@option("address", str, description="The Aternos-IP to check")
15+
async def checkip(self, ctx, address):
16+
address = check_ip(address)
17+
if not address:
18+
return await ctx.respond("Please provide a valid Aternos IP.", ephemeral=True)
2019
nip = address.split(".")[0]
21-
if len(nip) > 20:
22-
return await Utils.respond(ctx,
23-
"Aternos IPs can only be 20 characters long, please try a shorter one. Yours is " + str(
24-
len(nip)) + " characters long.")
25-
if len(nip) < 4:
26-
return await Utils.respond(ctx,
27-
"Aternos IPs must be at least 4 characters long, please try a longer one. Yours is " + str(
28-
len(nip)) + " characters long.")
20+
if len(nip) > 20 or len(nip) < 4:
21+
return await ctx.respond(f"Aternos IPs must contain between 4 to 20 characters. You have {len(nip)}/20 characters.", ephemeral=True)
2922
await ctx.defer()
3023
embed = Embed()
31-
server = await JavaServer.async_lookup(address)
32-
stat = await server.async_status()
24+
stat = await wait_for(get_server_status(address), timeout=2)
3325
if stat.version.name == "⚠ Error":
3426
embed.description = f"**{address}** is free to use!\nTo use it as your server address, head to **[the options of your server](https://aternos.org/options)**"
35-
embed.colour = Utils.Colors.green
27+
embed.colour = Colors.green
3628
else:
3729
embed.description = f"**{address}** is already taken!"
38-
embed.colour = Utils.Colors.red
39-
await Utils.respond(ctx=ctx, embed=embed)
30+
embed.colour = Colors.red
31+
await ctx.respond(embed=embed, ephemeral=True)
32+
4033

4134
def setup(bot: Bot):
4235
bot.add_cog(CheckIP(bot))

cogs/cogs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from discord.ext import commands
44
from discord import Option
55
from discord.ext.bridge import Bot
6-
from discord.ext.bridge.context import BridgeContext
7-
from utils import Utils
6+
from utilities.data import get_data
7+
88

99
class Cogs(commands.Cog):
1010
def __init__(self, bot: Bot):
1111
self.bot = bot
12-
self.info = Utils.get_data()
12+
self.info = get_data()
1313

14-
def getcogs(self, ctx: BridgeContext) -> list:
14+
def getcogs(self, ctx) -> list:
1515
if ctx.interaction.user.id not in self.info['Owners']:
1616
return ["You are not an owner of the bot!"]
1717
cogs = []
@@ -20,16 +20,15 @@ def getcogs(self, ctx: BridgeContext) -> list:
2020
cogs.append(file[:-3])
2121
return cogs
2222

23-
@slash_command(description='Only the owners of the bot can run this command',
24-
guild_ids=Utils.get_data()['FeatureGuilds'])
25-
async def cogs(self, ctx: BridgeContext, action: Option(choices=["Load", "Unload", "Reload"]), cog: Option(autocomplete=getcogs)):
23+
@slash_command(description='Only the owners of the bot can run this command', guild_ids=get_data()['FeatureGuilds'])
24+
async def cogs(self, ctx, action: Option(choices=["Load", "Unload", "Reload"]), cog: Option(autocomplete=getcogs)):
2625
if ctx.author.id not in self.info['Owners']:
2726
return
2827
if cog.lower() not in [f"{fn[:-3]}" for fn in listdir("./cogs")]:
29-
await Utils.respond(ctx, "That cog doesn't exist!")
28+
await ctx.respond("That cog doesn't exist!")
3029
return
3130
if action.lower() not in ["load", "unload", "reload"]:
32-
await Utils.respond(ctx, "That action doesn't exist!")
31+
await ctx.respond("That action doesn't exist!")
3332
return
3433
await ctx.defer()
3534
try:
@@ -40,14 +39,15 @@ async def cogs(self, ctx: BridgeContext, action: Option(choices=["Load", "Unload
4039
elif action == "Reload":
4140
self.bot.reload_extension(f"cogs.{cog}")
4241
except Exception as error:
43-
await Utils.respond(ctx, f"An error has occured!\n{error}")
42+
await ctx.respond(f"An error has occurred!\n{error}")
4443
raise error
4544
try:
4645
await self.bot.sync_commands()
4746
except Exception as error:
48-
await Utils.respond(ctx, f"An error has occured!\n{error}")
47+
await ctx.respond(f"An error has occurred!\n{error}")
4948
raise error
50-
await Utils.respond(ctx, f"{action}ed {cog} and reloaded all commands!")
49+
await ctx.respond(f"{action}ed {cog} and reloaded all commands!")
50+
5151

5252
def setup(bot: Bot):
5353
bot.add_cog(Cogs(bot))

cogs/error.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from discord.ext import commands
22
from discord.ext.bridge import Bot
3-
from utils import Utils
3+
44

55
class Error(commands.Cog):
66
def __init__(self, bot: Bot):
@@ -9,10 +9,10 @@ def __init__(self, bot: Bot):
99
@commands.Cog.listener()
1010
async def on_command_error(self, ctx, error):
1111
if isinstance(error, commands.CommandNotFound):
12-
return await Utils.respond(ctx, "That command doesn't exist!")
12+
return await ctx.respond("That command doesn't exist!")
1313
if isinstance(error, commands.MissingPermissions):
14-
return await Utils.respond(ctx, "You need the `Manage Server` permission to use this command.")
15-
await Utils.respond(ctx, "An unknown error has occured!\nThis has been logged")
14+
return await ctx.respond("You need the `Manage Server` permission to use this command.")
15+
await ctx.respond("An unknown error has occurred!\nThis has been logged")
1616
raise error
1717

1818
@commands.Cog.listener()
@@ -21,8 +21,9 @@ async def on_application_command_error(self, ctx, error):
2121
return await ctx.respond("This command is for owners only.")
2222
if isinstance(error, commands.GuildNotFound):
2323
return await ctx.respond("Could not find this guild.")
24-
await Utils.respond(ctx, "An unknown error has occured!\nThis has been logged")
24+
await ctx.respond("An unknown error has occurred!\nThis has been logged")
2525
raise error
2626

27+
2728
def setup(bot: Bot):
2829
bot.add_cog(Error(bot))

cogs/info.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from asyncio import wait_for
2-
from discord.ext import commands, bridge
3-
from discord.ext.bridge import Bot
4-
from discord import Embed
5-
from utils import Utils
2+
from discord import slash_command, Embed
3+
from discord.ext import commands
4+
from discord.ext.commands import Bot
5+
from utilities.data import Colors, get_server_status
6+
67

78
class Info(commands.Cog):
89
def __init__(self, bot: Bot):
910
self.bot = bot
1011

11-
@bridge.bridge_command(aliases=["information", "ping", "latency", "pong", "servers", "guilds", "support", "invite"], description = "Displays information about Pingernos")
12-
async def info(self, ctx: bridge.BridgeContext):
12+
@slash_command(aliases=["information", "ping", "latency", "pong", "servers", "guilds", "support", "invite"], description="Displays information about Pingernos")
13+
async def info(self, ctx):
1314
embed = Embed()
1415
try:
15-
stat = await wait_for(Utils.get_server_status("example.aternos.me"), timeout=2)
16+
stat = await wait_for(get_server_status("example.aternos.me"), timeout=2)
1617
except TimeoutError:
1718
latency = "N/A"
1819
else:
@@ -29,8 +30,9 @@ async def info(self, ctx: bridge.BridgeContext):
2930
3031
[[Invite]](https://discord.com/api/oauth2/authorize?client_id=889197952994791434&permissions=274878286912&scope=bot%20applications.commands) [[Support]](https://discord.gg/Ukr89GrMBk) [[Github]](https://github.com/BlackFurORG/pingernos) [[Privacy Policy]](https://gist.github.com/MiataBoy/20fda9024f277ea5eb2421adbebc2f23) [[Terms of Service]](https://gist.github.com/MiataBoy/81e96023a2aa055a038edab02e7e7792)
3132
"""
32-
embed.colour = Utils.Colors.blue
33-
await Utils.respond(ctx=ctx, embed=embed)
33+
embed.colour = Colors.blue
34+
await ctx.respond(embed=embed)
35+
3436

35-
def setup(bot: bridge.Bot):
37+
def setup(bot: Bot):
3638
bot.add_cog(Info(bot))

0 commit comments

Comments
 (0)