Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
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))