Exemple #1
0
    async def icon(self, ctx, user: discord.User = None):
        msg: discord.Message = ctx.message

        # Deletes the command message.
        await self.bot.delete_message(msg)

        embed: discord.Embed = discord.Embed()
        embed.colour = discord.Colour(Utils.getRandomColour())

        if user is not None:
            embed.title = "User Avatar"
            embed.description = f"Avatar for {user.mention}."
            embed.set_image(url=user.avatar_url)

            logMsg: str = f"{msg.author} requested {user}'s avatar."
        else:
            embed.title = "Server Icon"
            embed.description = f"Server icon for {msg.server.name}."
            embed.set_image(url=msg.server.icon_url)

            logMsg: str = f"{msg.author} requested {msg.server.name}'s " \
                          f"server icon."

        await self.bot.send_message(destination=msg.channel, embed=embed)
        self.log.info(logMsg)
Exemple #2
0
    async def created(self, ctx, channel: discord.Channel = None):
        msg: discord.Message = ctx.message

        if channel is None:
            channel = msg.channel

        embed: discord.Embed = discord.Embed()
        embed.colour = discord.Colour(Utils.getRandomColour())
        embed.title = "Channel Info"
        embed.description = f"Channel created at `{channel.created_at}`."

        await self.bot.send_message(destination=msg.channel, embed=embed)
Exemple #3
0
    async def wc(self,
                 ctx,
                 user: discord.User = None,
                 channel: discord.Channel = None,
                 limit: int = 1000,
                 colour: str = None):
        msg: discord.Message = ctx.message

        if user is None:
            user = msg.author

        if channel is None:
            channel = msg.channel

        # Deletes the command message.
        await self.bot.delete_message(msg)

        # Generates and posts a word cloud.
        imageFile: pathlib.Path = await self.getWordCloudImage(
            channel, user, limit, colour)
        await self.bot.send_file(msg.channel, imageFile)
        pathlib.Path.unlink(imageFile)

        # Retrieves the word cloud attachment's URL.
        # def check(message: discord.Message) -> bool:
        #     if message.attachments:
        #         return dict(message.attachments[0])["filename"] == os.path.basename(imageFile)
        #
        #     return False
        #
        # imageMessage = await self.bot.wait_for_message(author = msg.author,
        #                                                check = check)
        # imageURL: str = dict(imageMessage.attachments[0])["url"]
        # await self.bot.delete_message(imageMessage)

        # Embed properties.
        embed: discord.Embed = discord.Embed()
        embed.title = "Word Cloud"
        embed.description = f"Word cloud for {user.mention} in " \
                            f"{channel.mention}."
        embed.colour = discord.Colour(Utils.getRandomColour())
        # embed.set_image(url = imageURL)

        await self.bot.send_message(destination=msg.channel, embed=embed)

        self.log.info(f"{msg.author} generated a word cloud for {user} in "
                      f"{channel.server.name} #{channel.name}.")
Exemple #4
0
    async def sendMessage(self, msg: discord.Message, word: str):
        """
        Creates and sends an :class:`embed<discord.Embed>` which suggests
        possible alternatives for the word which triggered the Word Police.

        Parameters
        ----------
        msg: discord.Message
            The message which triggered the Word Police.
        word: str
            The word which triggered the Word Police.
        Returns
        -------
        None

        See Also
        -------
        discord.Client.send_message()
        discord.Embed()
        WordPolice.splitByLength()
        """
        embed: discord.Embed = discord.Embed()
        embed.title = "Word Police"
        embed.description = f"Stop right there, {msg.author.mention}!\n" \
                            "Perhaps you meant one of the following words " \
                            "instead?"
        embed.colour = Utils.getRandomColour()
        embed.set_thumbnail(url = self.config["thumbnail"])

        suggestions: Dict[int, List[str]] = self.splitByLength(self.config["words"][word.lower()])

        length: int
        lst: List[str]
        for length, lst in suggestions.items():
            value: str = ""

            for suggestion in lst:
                value += "\n" + suggestion

            embed.add_field(name = f"{length} Letters",
                            value = value)

        await self.bot.send_message(destination = msg.channel, embed = embed)
        self.log.info(f"{msg.author} triggered the word police in "
                      f"{msg.server.name} #{msg.channel.name}")
Exemple #5
0
    async def perms(self,
                    ctx,
                    user: discord.User = None,
                    channel: discord.Channel = None):
        msg: discord.Message = ctx.message

        if user is None:
            user = msg.author

        if channel is None:
            channel = msg.channel

        # Deletes the command message.
        await self.bot.delete_message(msg)

        perms: List[Permission] = self.getList(
            msg.channel.permissions_for(msg.author))

        if self.config["justify"]:
            width: int = self.getWidthMax(perms, self.config["padding"])
        else:
            width: int = 0

        embed: discord.Embed = discord.Embed()
        embed.colour = discord.Colour(Utils.getRandomColour())
        embed.title = "Member Permissions"
        embed.description = f"Permissions for {user.mention} in {channel.mention}."

        embed.add_field(name="General Permissions",
                        value=self.getString(perms, Category.GENERAL, width),
                        inline=False)

        embed.add_field(name="Text Permissions",
                        value=self.getString(perms, Category.TEXT, width),
                        inline=False)

        embed.add_field(name="Voice Permissions",
                        value=self.getString(perms, Category.VOICE, width),
                        inline=False)

        await self.bot.send_message(destination=msg.channel, embed=embed)
        self.log.info(f"{msg.author} retrieved {user}'s permissions for "
                      f"#{channel.name} in {msg.server.name} "
                      f"#{msg.channel.name}.")
Exemple #6
0
    async def id(self, ctx, *, user: discord.User = None):
        msg: discord.Message = ctx.message

        if user is None:
            user = msg.author

        embed: discord.Embed = discord.Embed()
        embed.title = "IDs"
        embed.description = f"IDs for {user.mention}."
        embed.colour = discord.Colour(Utils.getRandomColour())
        embed.add_field(name="User:"******"Current channel:",
                        value=msg.channel.id,
                        inline=False)
        embed.add_field(name="Current server:",
                        value=msg.server.id,
                        inline=False)

        await self.bot.delete_message(msg)
        await self.bot.send_message(destination=msg.channel, embed=embed)

        self.log.info(f"{msg.author} retrieved IDs in {msg.server.name} "
                      f"#{msg.channel.name}.")
Exemple #7
0
import os

import psycopg2

from Smashcords2BlogBot import Smashcords2BlogBot
from cogs import PermissionsManager, Utils
from cogs.Posts import Posts

if __name__ == "__main__":
    connection = psycopg2.connect(dbname=os.getenv("DBNAME"), user=os.getenv("DBUSER"), password=os.getenv("DBPASS"),
                                  host=os.getenv("DBHOST"), port=os.getenv("DBPORT"))
    bot = Smashcords2BlogBot(connection, command_prefix='$')
    bot.add_cog(Utils(bot))
    bot.add_cog(PermissionsManager(bot))
    bot.add_cog(Posts(bot))
    bot.run(os.getenv("BOT_TOKEN"))
Exemple #8
0
 def __init__(self, bot: commands.Bot):
     self.bot: commands.Bot = bot
     self.log: logging.Logger = logging.getLogger("bot.cogs.Permissions")
     self.log.info("cogs.Permissions loaded successfully.")
     self.config: Dict = Utils.loadConfig("Permissions")
Exemple #9
0
from discord.ext import commands
from typing import Pattern
import discord
import re

import Logging
import cogs.Utils as Utils

# Loads the configuration file.
config: dict = Utils.loadConfig("Bot")
name: str = config["name"]
isSelfBot: bool = config["isSelfBot"]

bot: commands.Bot = commands.Bot(command_prefix = config["prefixes"],
                                 description = name,
                                 self_bot = isSelfBot,
                                 pm_help = None,
                                 help_attrs = dict(hidden = True))

@bot.event
async def on_ready():
    """
    Called when the :class:`client<discord.Client>` is done preparing the data
    received from Discord. Usually after login is successful and the
    Client.servers and co. are filled up.

    Note
    -------
    This function is not guaranteed to be the first event called. Likewise, this
    function is not guaranteed to only be called once. This library implements
    reconnection logic and thus will end up calling this event whenever a RESUME
Exemple #10
0
 def __init__(self, bot: commands.Bot):
     self.bot: commands.Bot = bot
     self.log: logging.Logger = logging.getLogger("bot.cogs.WordPolice")
     self.log.info("cogs.WordPolice loaded successfully.")
     self.config: Dict = Utils.loadConfig("WordPolice")
     self.pattern = self.getPattern(self.config["words"])