Added .gitignore, Added Inspirobot
This commit is contained in:
parent
ca91cfddaf
commit
2f16876177
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.json
|
||||
*.txt
|
||||
__pycache__
|
11
api/inspirobot.py
Normal file
11
api/inspirobot.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import requests
|
||||
from util import logging
|
||||
|
||||
def get_inspirational_quote() -> str:
|
||||
response = requests.get("http://inspirobot.me/api?generate=true")
|
||||
|
||||
if not response.ok:
|
||||
logging.error(f"Steam API response not OK: {response.status_code} [http://inspirobot.me/api?generate=true]")
|
||||
return None
|
||||
|
||||
return response.text
|
22
bot.py
22
bot.py
|
@ -11,15 +11,29 @@ client = commands.Bot(command_prefix='.', case_insensitive=True)
|
|||
@client.command()
|
||||
@commands.is_owner()
|
||||
async def load(ctx, extension):
|
||||
client.load_extension(f"cogs.{extension}")
|
||||
await ctx.message.add_reaction("👍")
|
||||
try:
|
||||
client.load_extension(f"cogs.{extension}")
|
||||
await ctx.message.add_reaction("👍")
|
||||
except:
|
||||
await ctx.message.add_reaction("👎")
|
||||
|
||||
@client.command()
|
||||
@commands.is_owner()
|
||||
async def unload(ctx, extension):
|
||||
client.unload_extension(f"cogs.{extension}")
|
||||
await ctx.message.add_reaction("👍")
|
||||
try:
|
||||
client.unload_extension(f"cogs.{extension}")
|
||||
await ctx.message.add_reaction("👍")
|
||||
except:
|
||||
await ctx.message.add_reaction("👎")
|
||||
|
||||
@client.command()
|
||||
@commands.is_owner()
|
||||
async def reload(ctx, extension):
|
||||
try:
|
||||
client.reload_extension(f"cogs.{extension}")
|
||||
await ctx.message.add_reaction("👍")
|
||||
except:
|
||||
await ctx.message.add_reaction("👎")
|
||||
|
||||
|
||||
@client.event
|
||||
|
|
23
cogs/api/inspirobot.py
Normal file
23
cogs/api/inspirobot.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import discord
|
||||
|
||||
from discord.ext import commands
|
||||
from api import inspirobot
|
||||
|
||||
class Inspirobot(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="Inspirobot", description="Sends a randomly generated inspirational quote", aliases=["inspiration", "inspiro"])
|
||||
@commands.cooldown(1, 5)
|
||||
async def inspirobot(self, ctx):
|
||||
image = inspirobot.get_inspirational_quote()
|
||||
if image is None:
|
||||
await ctx.message.add_reaction("⚠️")
|
||||
else:
|
||||
embed = discord.Embed(title="InspiroBot", color=0x111387)
|
||||
embed.set_image(url=image)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Inspirobot(client))
|
|
@ -11,11 +11,13 @@ class Steam(commands.Cog):
|
|||
@commands.cooldown(1, 2)
|
||||
async def SteamLevel(self, ctx, vanity_url):
|
||||
level = steam.get_steam_level(vanity_url)
|
||||
percentile = round(float(steam.get_steam_level_distribution(level)), 2)
|
||||
if level is not None:
|
||||
await ctx.send(f"{vanity_url} is level {level}! This makes him better than {percentile}% of Steam users!")
|
||||
else:
|
||||
|
||||
if level is None:
|
||||
await ctx.send(f"There is nobody named \"{vanity_url}\" on Steam, or their profile might be pivate.")
|
||||
else:
|
||||
percentile = round(float(steam.get_steam_level_distribution(level)), 2)
|
||||
await ctx.send(f"{vanity_url} is level {level}! This makes him better than {percentile}% of Steam users!")
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue