Exemple #1
0
    async def stackoverflow(self, ctx: commands.Context, *,
                            search_query: str) -> None:
        """Sends the top 5 results of a search query from stackoverflow."""
        params = SO_PARAMS | {"q": search_query}
        async with http_session.get(url=BASE_URL, params=params) as response:
            if response.status == 200:
                data = await response.json()
            else:
                logger.error(
                    f'Status code is not 200, it is {response.status}')
                await ctx.send(embed=ERR_EMBED)
                return
        if not data['items']:
            no_search_result = Embed(
                title=f"No search results found for {search_query}",
                color=Color.dark_theme())
            await ctx.send(embed=no_search_result)
            return

        top5 = data["items"][:5]
        encoded_search_query = quote_plus(search_query)
        embed = Embed(title="Search results - Stackoverflow",
                      url=SEARCH_URL.format(query=encoded_search_query),
                      description=f"Here are the top {len(top5)} results:",
                      color=Color.dark_theme())
        for item in top5:
            embed.add_field(name=unescape(item['title']),
                            value=(f"[⬆ {item['score']}    "
                                   f"👀 {item['view_count']}     "
                                   f"💬 {item['answer_count']}   "
                                   f"🏷 {', '.join(item['tags'][:3])}]"
                                   f"({item['link']})"),
                            inline=False)
        embed.set_footer(text="View the original link for more results.")

        try:
            await ctx.send(embed=embed)
        except HTTPException:
            search_query_too_long = Embed(
                title=
                "Your search query is too long, please try shortening your search query",
                color=Color.dark_theme())
            await ctx.send(embed=search_query_too_long)
Exemple #2
0
    async def my_tags(self, ctx: Context):
        """Shows your own tags."""
        query = await ctx.pool.fetch("SELECT * FROM tags WHERE guild_id = $1",
                                     ctx.guild.id)

        if len(query) == 0 or query is None:
            await ctx.send("No tags found.")
        else:
            fmt = "\n".join(tag["tag_name"] + " " + f"(ID: {tag['tag_id']})"
                            for tag in query)
            e = Embed(color=Color.dark_theme(), description=fmt)
            e.set_author(name=ctx.author.name, icon_url=ctx.author.avatar)
            await ctx.send(embed=e)
Exemple #3
0
 async def ip(self, ctx):
     embed = Embed(
         title="Basement Minecraft Servers",
         description=
         "__**Info**__\nYour Minecraft version should match **1.17**.",
         color=Color.dark_theme())
     embed.add_field(
         name="Server 1",
         value=
         "**IP Address**:`billysbasement.aternos.me`\n**OP**:<@!621397007332016145>",
         inline=False)
     embed.add_field(
         name="Server 2",
         value=
         "**IP Address**:`147.135.71.70:25592`\n**OP**:<@!517998886141558786>",
         inline=False)
     await ctx.send(embed=embed)
Exemple #4
0
import discord
from discord import Embed, HTTPException, Color
from discord.ext import commands

from libs.httpsession import http_session

BASE_URL = "https://api.stackexchange.com/2.2/search/advanced"
SO_PARAMS = {"order": "desc", "sort": "activity", "site": "stackoverflow"}
SEARCH_URL = "https://stackoverflow.com/search?q={query}"
ERR_EMBED = Embed(
    title="Error in fetching results from Stackoverflow",
    description=
    ("Sorry, there was en error while trying to fetch data from the Stackoverflow website. Please try again in some "
     "time. If this issue persists, please contact the staff or send a message in #dev-contrib."
     ),
    color=Color.dark_theme())


class Stackoverflow(commands.Cog):
    """Contains command to interact with stackoverflow from discord."""
    def __init__(self, bot):
        self.bot = bot

    @commands.command(aliases=["so"])
    @commands.cooldown(1, 15, commands.cooldowns.BucketType.user)
    async def stackoverflow(self, ctx: commands.Context, *,
                            search_query: str) -> None:
        """Sends the top 5 results of a search query from stackoverflow."""
        params = SO_PARAMS | {"q": search_query}
        async with http_session.get(url=BASE_URL, params=params) as response:
            if response.status == 200:
Exemple #5
0
    async def serverinfo(self, ctx):
        status1 = None
        status2 = None
        try:
            server1 = MinecraftServer.lookup("billysbasement.aternos.me:54987")
            status1 = server1.status()
        except:
            pass
        try:
            server2 = MinecraftServer.lookup("147.135.71.70:25592")
            status2 = server2.status()
        except:
            pass

        embed = Embed(
            title="Basement Minecraft Servers Info",
            description=
            "__**Info**__\nAsk the OP's for help if you can't join the server.\nPing them if the server is offline and you want to join, they will help you.",
            color=Color.dark_theme())

        if status1 is None and status2 is None:
            embed.add_field(
                name="Servers are Offline",
                value=
                "Sorry both of the servers are offline at the moment. Please Try asking server OP's.",
                inline=False)

        if status1 is not None:
            embed.add_field(
                name="Server 1",
                value=
                "**IP Address**: `billysbasement.aternos.me`\n**OP**: <@!621397007332016145>\n**Status**: 🟢 Online\n**Players Online**: {0}\n**Minecraft Version:** {1}\n**Latency**: {2}"
                .format(status1.players.online, status1.version.name,
                        status1.latency),
                inline=False)
        else:
            embed.add_field(
                name="Server 1",
                value=
                "IP Address: `billysbasement.aternos.me`\nOP: <@!621397007332016145>\nStatus: âš« Offline\n"
                .format(),
                inline=False)

        if status2 is not None:
            embed.add_field(
                name="Server 2",
                value=
                "**IP Address**: `147.135.71.70:25592`\n**OP**: <@!517998886141558786>\n**Status**: 🟢 Online\n**Players Online**: {0}\n**Minecraft Version:** {1}\n**Latency**: {2}"
                .format(status2.players.online, status2.version.name,
                        status2.latency),
                inline=False)
        else:
            embed.add_field(
                name="Server 2",
                value=
                "IP Address: `147.135.71.70:25592`\nOP: <@!517998886141558786>\nStatus: âš« Offline\n"
                .format(),
                inline=False)

        embed.set_footer(text=f"Requested by {ctx.author.name}",
                         icon_url=ctx.author.avatar_url)

        await ctx.send(embed=embed)
Exemple #6
0
 async def coord(self, ctx, x=0, y=0, z=0):
     await ctx.send(
         embed=Embed(title="",
                     description=f"X: **{x}**, Y: **{y}**, Z: **{z}**",
                     color=Color.dark_theme()))
Exemple #7
0
def getStockColor(stock):
    return Color.dark_theme()