-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Soapy7261/main
Python rewrite
- Loading branch information
Showing
21 changed files
with
456 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Pylint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.10.9", "3.11.1"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install pylint | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Analysing the code with pylint | ||
run: | | ||
pylint $(git ls-files '*.py') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
config.json | ||
node_modules | ||
.env | ||
.env.local | ||
.env.development | ||
local.gitignore | ||
.idea | ||
.vscode | ||
cogs/__pycache__ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[MESSAGES CONTROL] | ||
disable=line-too-long,missing-function-docstring,missing-class-docstring,missing-module-docstring,too-few-public-methods,no-name-in-module,global-statement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Configuration | ||
Pingernos py offers three different ways to configure it, a config file, environment variables and a .env | ||
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. | ||
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. | ||
Environment variables use `SCREAMING_SNAKE_CASE`, the configuration file uses `PascalCase`. | ||
|
||
If a config file is missing, pingernos will try to load the environment variables. If both are missing, pingernos will exit. | ||
|
||
## Auth Token (required) | ||
Discord bot authentication token, can be generated in the [Developer Portal](https://discord.com/developers/applications/) | ||
|
||
| type | config file | environment | | ||
|--------|-------------|---------------------| | ||
| string | `Token` | `TOKEN` | | ||
|
||
## Prefix (required) | ||
Prefix to use for commands, can be a mention or a string | ||
|
||
| type | config file | environment | | ||
|--------|-------------|---------------------| | ||
| string | `Prefix` | `PREFIX` | | ||
|
||
## Owners (required) | ||
Array of user ids that are allowed to use owner only features | ||
|
||
| type | config file | environment | | ||
|----------|--------------------|----------------------------| | ||
| string[] | `Owners` | `OWNERS` | | ||
|
||
## Database (required) | ||
MySQL/MariaDB access credentials. Other SQL dialects or Databases are not supported. | ||
|
||
### Host | ||
Database hostname or IP | ||
|
||
| type | config file | environment | | ||
|--------|-----------------|------------------------| | ||
| string | `Database.Host` | `DB_HOST` | | ||
|
||
### User | ||
Database username | ||
|
||
| type | config file | environment | | ||
|--------|-----------------|------------------------| | ||
| string | `Database.User` | `DB_USER` | | ||
|
||
### Password | ||
Database password | ||
|
||
| type | config file | environment | | ||
|--------|---------------------|----------------------------| | ||
| string | `Database.Password` | `DB_PASSWORD` | | ||
|
||
### Database | ||
Database name | ||
|
||
| type | config file | environment | | ||
|--------|---------------------|----------------------------| | ||
| string | `Database.Database` | `DB_DATABASE` | | ||
|
||
### Port | ||
Database port | ||
|
||
| type | config file | environment | | ||
|--------|-----------------|------------------------| | ||
| int | `Database.Port` | `DB_PORT` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#from re import match | ||
from discord.ext import commands, bridge | ||
from discord import Embed | ||
from mcstatus import JavaServer | ||
from utils import Utils | ||
class CheckIP(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@bridge.bridge_command(aliases=["checkserverip", "check"], description="Checks if an Aternos-IP is free to use.") | ||
async def checkip(self, ctx, address = None): | ||
if address is None: | ||
return await ctx.respond("Please provide a Aternos server ip!\nExample: example.aternos.me") | ||
#if not match(r"^(\w+)(?:\.aternos\.me)?$", address): | ||
# return await ctx.respond(f"`{address}`is not a valid Aternos server IP or name.") | ||
if not address.endswith(".aternos.me"): | ||
address += ".aternos.me" | ||
if address.count(".") > 2: | ||
return await ctx.respond("Please provide a valid Aternos server ip!\nExample: example.aternos.me") | ||
nip = address.split(".")[0] | ||
if len(nip) > 20: | ||
return await ctx.respond("Aternos IPs can only be 20 characters long, please try a shorter one. Yours is " + str(len(nip)) + " characters long.") | ||
if len(nip) < 4: | ||
return await ctx.respond("Aternos IPs must be at least 4 characters long, please try a longer one. Yours is " + str(len(nip)) + " characters long.") | ||
#async with ctx.typing(): | ||
await ctx.defer() | ||
embed = Embed() | ||
server = await JavaServer.async_lookup(address) | ||
stat = await server.async_status() | ||
if stat.version.name == "⚠ Error": | ||
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)**" | ||
embed.colour = Utils.Colors.green | ||
else: | ||
embed.description=f"**{address}** is already taken!" | ||
embed.colour = Utils.Colors.red | ||
await ctx.respond(embed=embed) | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(CheckIP(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from os import listdir | ||
from discord.ext.commands import slash_command | ||
from discord.ext import commands | ||
from discord import Option | ||
#from discord.errors import ExtensionAlreadyLoaded | ||
from utils import Utils | ||
class Cogs(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
self.info = Utils.get_data() | ||
|
||
def getcogs(self, ctx): | ||
if ctx.interaction.user.id not in self.info['Owners']: | ||
return ["You are not an owner of the bot!"] | ||
cogs = [] | ||
for file in listdir("./cogs"): | ||
if file.endswith(".py"): | ||
cogs.append(file[:-3]) | ||
return cogs | ||
|
||
@slash_command(description='Only the owners of the bot can run this command', guild_ids=[1041398130677141564]) | ||
async def cogs(self, ctx, action: Option(choices=["Load", "Unload", "Reload"]), cog: Option(autocomplete=getcogs)): | ||
if ctx.author.id not in self.info['Owners']: | ||
return | ||
if cog.lower() not in [f"{fn[:-3]}" for fn in listdir("./cogs")]: | ||
await ctx.respond("That cog doesn't exist!", ephemeral=True) | ||
return | ||
if action.lower() not in ["load", "unload", "reload"]: | ||
await ctx.respond("That action doesn't exist!", ephemeral=True) | ||
return | ||
await ctx.defer() | ||
try: | ||
if action == "Load": | ||
self.bot.load_extension(f"cogs.{cog}") | ||
elif action == "Unload": | ||
self.bot.unload_extension(f"cogs.{cog}") | ||
elif action == "Reload": | ||
self.bot.reload_extension(f"cogs.{cog}") | ||
except Exception as error: | ||
await ctx.respond(f"An error has occured!\n{error}") | ||
raise error | ||
try: | ||
await self.bot.sync_commands() | ||
except Exception as error: | ||
await ctx.respond(f"An error has occured!\n{error}") | ||
raise error | ||
await ctx.respond(f"{action}ed {cog} and reloaded all commands!") | ||
|
||
def setup(bot): | ||
bot.add_cog(Cogs(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from discord.ext import commands | ||
class Error(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_command_error(self, ctx, error): | ||
if isinstance(error, commands.CommandNotFound): | ||
return await ctx.respond("That command doesn't exist!") | ||
await ctx.respond ("An unknown error has occured!\nThis has been logged") | ||
raise error | ||
|
||
@commands.Cog.listener() | ||
async def on_application_command_error(self, ctx, error): | ||
await ctx.respond ("An unknown error has occured!\nThis has been logged") | ||
raise error | ||
|
||
def setup(bot): | ||
bot.add_cog(Error(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from discord.ext import commands, bridge | ||
from discord import Embed | ||
from utils import Utils | ||
class Guilds(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@bridge.bridge_command(aliases=["servers"], description = "Shows how many guilds the bot is in.") | ||
async def guilds(self, ctx): | ||
embed = Embed() | ||
embed.description = f"{self.bot.user.name} is currently in {len(self.bot.guilds)} servers with a total of {sum(x.member_count for x in self.bot.guilds)} users." | ||
embed.color = Utils.Colors.blue | ||
await ctx.respond(embed=embed) | ||
|
||
def setup(bot): | ||
bot.add_cog(Guilds(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from asyncio import wait_for | ||
from discord.ext import commands, bridge | ||
from utils import Utils | ||
class Ping(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@bridge.bridge_command(aliases=["latency", "pong"], description="Get the bot and websocket latency") | ||
async def ping(self, ctx): | ||
#await ctx.defer() | ||
try: | ||
stat = await wait_for(Utils.get_server_status("example.aternos.me"), timeout=2) | ||
except TimeoutError: | ||
return await ctx.respond(f"Uh oh! The protocol took too long to respond! This will likely fix itself.\nAPI Latency is {round(self.bot.latency*1000, 2)}ms") | ||
await ctx.respond(content=f"API Latency is {round(self.bot.latency*1000, 2)}ms\nProtocol: {round(stat.latency)}ms") | ||
|
||
def setup(bot): | ||
bot.add_cog(Ping(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from discord.ext import commands, bridge | ||
from discord import Embed | ||
from utils import Utils | ||
class Privacy(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@bridge.bridge_command(description = "Shows the privacy policy of the bot.") | ||
async def privacy(self, ctx): | ||
embed = Embed() | ||
embed.description = f"{self.bot.user.name} saves a minimal amount of data to allow for its functionality. As we work on regaining full functionality, we do not currently collect anything On our database storage, we currently only have server IPs and guild IDs stored. For any concerns, Mail to [email protected]" | ||
embed.colour = Utils.Colors.blue | ||
await ctx.respond(embed=embed) | ||
|
||
def setup(bot): | ||
bot.add_cog(Privacy(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from discord.ext import commands#, bridge | ||
class SetServer(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
#@bridge.bridge_command(aliases=["set"], description="Set the default server to use if no argument is provided in the status command.") | ||
#async def setserver(self, ctx, server = None): | ||
# if server is None: | ||
# return await ctx.respond("Please provide a server IP.") | ||
# await ctx.defer() | ||
#This is up to Miataboy to implement | ||
|
||
def setup(bot): | ||
bot.add_cog(SetServer(bot)) |
Oops, something went wrong.