Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
2,121 additions
and
272 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
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,77 @@ | ||
import asyncio | ||
import discord | ||
import aiohttp | ||
import json | ||
from botClient import colorCode, adminId | ||
from discord.ext import commands | ||
|
||
"""Module for admin-only commands""" | ||
|
||
class AdminFunctions: | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
"""Checks if the command author is the admin of the bot, otherwise returns False.""" | ||
"""adminId is provided by the botClient module""" | ||
async def is_admin(ctx): | ||
return ctx.author.id == adminId | ||
@commands.command(aliases=['ip', 'clientip', 'ipclient']) | ||
@commands.cooldown(2, 4, commands.BucketType.user) | ||
@commands.check(is_admin) | ||
async def ip_command(self, ctx): | ||
"""Returns the current IP address of the bot client""" | ||
try: | ||
await ctx.message.delete() | ||
except discord.HTTPException: | ||
pass | ||
"""Fetches data from the IP API site, then using JSON to format we show it through an embed""" | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get('http://ip-api.com/json/') as req: | ||
resp = json.loads(await req.text()) | ||
if req.status == 200: | ||
embed = discord.Embed(title='Internet Info', color=colorCode[0]) | ||
embed.add_field(name='IP Address', value=resp['query'], inline=True) | ||
embed.add_field(name='ISP Name', value=resp['isp'], inline=True) | ||
embed.add_field(name='Autonomous System #', value=resp['as'], inline=True) | ||
embed.add_field(name='City', value=resp['city'], inline=True) | ||
embed.add_field(name='Zip Address', value=resp['zip'], inline=True) | ||
embed.add_field(name='Region', value=f"{resp['regionName']} ({resp['region']})", inline=True) | ||
embed.add_field(name='Country', value=f"{resp['country']} ({resp['countryCode']})", inline=True) | ||
await ctx.send(embed=embed) | ||
|
||
else: | ||
print(f'Error, Req Status: {req.status}') | ||
|
||
@ip_command.error | ||
async def ip_command_error(self, ctx, error): | ||
"""If the admin check returns False, informs the user they don't have permission""" | ||
if isinstance(error, commands.CheckFailure): | ||
#if ctx.message.guild == None: | ||
# await ctx.send('This command is only available in server/guild channels.') | ||
# return | ||
await ctx.send('You do not have permission to use this command.') | ||
|
||
#async def is_admin(ctx): | ||
# return ctx.author.id == 65810928695771136 | ||
@commands.command(aliases =['sleep']) | ||
@commands.check(is_admin) | ||
async def sleep_command(self, ctx, seconds = 10): | ||
"""Puts the bot on standby for a chosen amount of seconds, maximum 1 minute (60)""" | ||
if seconds > 60: | ||
await ctx.send ("I'm not allowed to sleep for more than 1 minute.") | ||
return | ||
await ctx.message.channel.send(f'Going to sleep for {seconds} seconds.') | ||
await asyncio.sleep(seconds) | ||
await ctx.message.channel.send('Done sleeping, thanks.') | ||
|
||
@sleep_command.error | ||
async def sleep_command_error(self, ctx, error): | ||
if isinstance(error, commands.CheckFailure): | ||
#if ctx.message.guild == None: | ||
# await ctx.send('This command is only available in server/guild channels.') | ||
# return | ||
await ctx.send('You do not have permission to use this command.') | ||
|
||
|
||
def setup(client): | ||
client.add_cog(AdminFunctions(client)) |
Oops, something went wrong.