Skip to content
Permalink
Browse files
Deleted useless checks
  • Loading branch information
stavilam committed Nov 28, 2018
1 parent 1810815 commit 30bbc4805d3380e5bef0e913292881c5a4797863
Showing 1 changed file with 27 additions and 33 deletions.
@@ -1,25 +1,34 @@
import asyncio
import discord
from discord.ext import commands
import sys, traceback
import aiohttp
import json
from botClient import colorCode
from botClient import colorCode, adminId
from discord.ext import commands
from botClient import client

"""Module for admin-only commands"""

class AdminFunctions:
def __init__(self,client):
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.has_role('Owner')
@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:
# print (json.dumps(resp, sort_keys=True, indent=4)) #for testing purposes
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)
@@ -35,34 +44,19 @@ class AdminFunctions:

@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.author.id == 65810928695771136:
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:
# print (json.dumps(resp, sort_keys=True, indent=4)) #for testing purposes
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)
return

if ctx.message.guild == None:
await ctx.send('This command is only available in server/guild channels.')
return
await ctx.send('Your role does not have permission to use this command.')
#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
#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
@@ -73,9 +67,9 @@ class AdminFunctions:
@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
#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.')


0 comments on commit 30bbc48

Please sign in to comment.