Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions futaba/cogs/misc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
from .core import Miscellaneous
from .debug import Debugging
from .mentionable import Mentionable
from .inspirobot import InspiroBot

# Setup for when cog is loaded
def setup(bot):
setup_miscellaneous(bot)
setup_debugging(bot)
setup_mentionable(bot)
setup_inspirobot(bot)


def setup_miscellaneous(bot):
Expand All @@ -38,11 +40,17 @@ def setup_mentionable(bot):
bot.add_cog(cog)


def setup_inspirobot(bot):
cog = InspiroBot(bot)
bot.add_cog(cog)


# Remove all the cogs when cog is unloaded
def teardown(bot):
teardown_miscellaneous(bot)
teardown_debugging(bot)
teardown_mentionable(bot)
teardown_inspirobot(bot)


def teardown_miscellaneous(bot):
Expand All @@ -55,3 +63,7 @@ def teardown_debugging(bot):

def teardown_mentionable(bot):
bot.remove_cog(Mentionable.__name__)


def teardown_inspirobot(bot):
bot.remove_cog(InspiroBot.__name__)
53 changes: 53 additions & 0 deletions futaba/cogs/misc/inspirobot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# cogs/misc/inspirobot.py
#
# futaba - A Discord Mod bot for the Programming server
# Copyright (c) 2017-2020 Jake Richardson, Ammon Smith, jackylam5
#
# futaba is available free of charge under the terms of the MIT
# License. You are free to redistribute and/or modify it under those
# terms. It is distributed in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY. See the LICENSE file for more details.
#

""" Cog for InspiroBot image generation. """

import logging

import aiohttp
import discord
from discord.ext import commands

from ..abc import AbstractCog

logger = logging.getLogger(__name__)

__all__ = ["InspiroBot"]

INSPIROBOT_API = "https://inspirobot.me/api?generate=true"


class InspiroBot(AbstractCog):
__slots__ = ("journal",)

def __init__(self, bot):
super().__init__(bot)
self.journal = bot.get_broadcaster("/inspirobot")

def setup(self):
pass

@commands.command(name="inspirobot", aliases=["inspire", "inspireme"])
async def inspirobot(self, ctx):
""" Returns an image generated by InspiroBot. """
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with session.get(INSPIROBOT_API) as api_resp:
image_url = await api_resp.text()

content = f"Got generated image {image_url} from InspiroBot"
self.journal.send("api/success", ctx.guild, content, icon="ok")

embed = discord.Embed()
embed.title = "Be inspired."
embed.set_image(url=image_url)
await ctx.send(embed=embed)