-
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 #56 from BlueAtomic/rewrite
- Loading branch information
Showing
16 changed files
with
302 additions
and
297 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ config.json | |
.idea | ||
.vscode | ||
cogs/__pycache__ | ||
__pycache__ | ||
__pycache__ | ||
venv |
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
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 |
---|---|---|
@@ -1,42 +1,35 @@ | ||
from discord.ext import commands, bridge | ||
from discord import Embed | ||
from mcstatus import JavaServer | ||
from discord.ext.bridge import Bot | ||
from discord.ext.bridge.context import BridgeContext | ||
from utils import Utils | ||
from asyncio import wait_for | ||
from discord import slash_command, option, Embed | ||
from discord.ext import commands | ||
from discord.ext.commands import Bot | ||
from utilities.data import Colors, get_server_status | ||
from utilities.utility import check_ip | ||
|
||
|
||
class CheckIP(commands.Cog): | ||
def __init__(self, bot: 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: BridgeContext, address=None): | ||
if address is None: | ||
return await Utils.respond(ctx, "Please provide a Aternos server ip!\nExample: example.aternos.me") | ||
if not address.endswith(".aternos.me"): | ||
address += ".aternos.me" | ||
if address.count(".") > 2: | ||
return await Utils.respond(ctx, "Please provide a valid Aternos server ip!\nExample: example.aternos.me") | ||
@slash_command(aliases=["checkserverip", "check"], description="Checks if an Aternos-IP is free to use.") | ||
@option("address", str, description="The Aternos-IP to check") | ||
async def checkip(self, ctx, address): | ||
address = check_ip(address) | ||
if not address: | ||
return await ctx.respond("Please provide a valid Aternos IP.", ephemeral=True) | ||
nip = address.split(".")[0] | ||
if len(nip) > 20: | ||
return await Utils.respond(ctx, | ||
"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 Utils.respond(ctx, | ||
"Aternos IPs must be at least 4 characters long, please try a longer one. Yours is " + str( | ||
len(nip)) + " characters long.") | ||
if len(nip) > 20 or len(nip) < 4: | ||
return await ctx.respond(f"Aternos IPs must contain between 4 to 20 characters. You have {len(nip)}/20 characters.", ephemeral=True) | ||
await ctx.defer() | ||
embed = Embed() | ||
server = await JavaServer.async_lookup(address) | ||
stat = await server.async_status() | ||
stat = await wait_for(get_server_status(address), timeout=2) | ||
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 | ||
embed.colour = Colors.green | ||
else: | ||
embed.description = f"**{address}** is already taken!" | ||
embed.colour = Utils.Colors.red | ||
await Utils.respond(ctx=ctx, embed=embed) | ||
embed.colour = Colors.red | ||
await ctx.respond(embed=embed, ephemeral=True) | ||
|
||
|
||
def setup(bot: 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
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
Oops, something went wrong.