Skip to content
Permalink
Browse files
new file
  • Loading branch information
emrulovd committed Nov 29, 2018
2 parents 896d2a9 + 7d297f7 commit 8e4ae6170bea81f1b4229e59cb3c178d4129bfbe
Show file tree
Hide file tree
Showing 15 changed files with 2,121 additions and 272 deletions.
@@ -53,10 +53,32 @@ Also, the discord.py 1.0 REWRITE library is new, it's been scheduled to fully re

Important Links:
-----------------------------------------------------------------------
https://discordpy.readthedocs.io/en/rewrite/migrating.html
https://discordpy.readthedocs.io/en/latest/faq.html
https://discordpy.readthedocs.io/en/rewrite/ext/commands/commands.html
https://discordpy.readthedocs.io/en/rewrite/api.html
https://discordpy.readthedocs.io/en/rewrite/migrating.html - Discord.py 1.0 rewrite migrating

https://discordpy.readthedocs.io/en/latest/faq.html - Discord.py FAQ

https://discordpy.readthedocs.io/en/rewrite/ext/commands/commands.html - Discord.py commands docs

https://discordpy.readthedocs.io/en/rewrite/api.html - Discord.py API docs

https://discordapp.com/developers/docs/resources/channel - Official Discord API docs

https://docs.python.org/3/library/functions.html - Python integrated functions

https://jeffknupp.com/blog/2016/03/07/python-with-context-managers/ - Python context managers explanation

https://aiohttp.readthedocs.io/en/stable/client_reference.html - Aiohttp Client Ref. Docs

https://realpython.com/python-json/#a-very-brief-history-of-json - JSON explanation

https://docs.python.org/3/library/json.html - JSON docs

https://www.json.org/ - Official JSON page explanation

https://www.w3schools.com/python/python_mysql_getstarted.asp - MySQL Python Guide

https://www.makeuseof.com/tag/important-sql-commands-programmer-know/ - Some MySQL commands

-----------------------------------------------------------------------
Tutorials:
-----------------------------------------------------------------------
@@ -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))

0 comments on commit 8e4ae61

Please sign in to comment.