Exemple #1
0
async def translate(message):
    message_content = MiscellaneousCog.removeEmojiAndPings(message.content)
    if len(message_content) < 2 or message.content == '' or message.content.startswith('.'):
        return

    if not SettingsController(message.guild).get_setting("google", "translate"):
        return

    languages = SettingsController(message.guild).get_option("google", "translate", "languages")
    # print(languages)
    text = Text(message_content)
    guess = text.language.code
    # print(guess)
    if guess != 'en' and guess in languages:  # and guess.confidence > 0.8:
        # print(translator.translate(message_content, src=guess.lang).text + "  source: =" + message_content)
        try:
            translation = str(TextBlob(message_content).translate())
        except NotTranslated:
            return
        if translation.lower() == message_content.lower():
            return
        embed = discord.Embed(title='@' + message.author.display_name + " said [{}]".format(guess),
                              description=translation,
                              color=0xf0f0f0)
        await message.channel.send(embed=embed)
async def on_message_delete(message):
    if message.author == client.user:
        return

    if not SettingsController(message.guild).get_setting("logging", "on_edit"):
        return
    channel = SettingsController(message.guild).get_option("logging", "on_edit", "channel_to_post_in")
    embed = discord.Embed(title='@' + message.author.display_name,
                          description="Message deleted in {}".format(message.channel.name),
                          color=0xf0f0f0)
    embed.add_field(name="Message", value=message.content, inline=False)
    await discord.utils.get(message.guild.channels, id=int(channel)).send(embed=embed)
async def on_message_edit(before, after):
    if after.author == client.user or before.content == after.content:
        return

    if not SettingsController(after.guild).get_setting("logging", "on_edit"):
        return
    channel = SettingsController(after.guild).get_option("logging", "on_edit", "channel_to_post_in")
    embed = discord.Embed(title='@' + after.author.display_name,
                          description="Message edited in {}".format(after.channel.name),
                          color=0xf0f0f0)
    embed.add_field(name="Before", value=before.content, inline=False)
    embed.add_field(name="After", value=after.content, inline=False)
    embed.add_field(name='Edited at', value=after.edited_at, inline=False)
    embed.add_field(name="Jump to message", value=after.jump_url)
    await discord.utils.get(after.guild.channels, id=int(channel)).send(embed=embed)
Exemple #4
0
async def copypasta_on_msg(message):
    """
    Used to check if the message is  copy pasta.
    Full implementation in copypasta
    :param message: Discord.py message Class
    :return: None
    """
    global last_used_time  # Load global
    # Admins get to dodge the cooldown
    if not message.author.top_role.permissions.administrator:
        # If user is not an admin and triggers a copypasta during the cooldown stop executing
        if last_used_time + 15 > time.time():
            return
    if not SettingsController(message.guild).get_setting(
            "copypasta", "respond"):
        return
    pasta_controller = CopyPastaController(
        message.guild)  # Load the controller

    if message.content in pasta_controller.pastas.pasta_dict:  # If the message is in the dict keys
        contents = pasta_controller.get_dict()[message.content]  # Found
        if contents[
                1] == 1:  # If bits for the copypasta are set to 1 remove the trigger message
            await message.delete()
        print(pasta_controller.get_dict())
        await message.channel.send(contents[0])  # Print the copypasta
        return
def is_enabled(message):
    command = message.content.split()[0][1:]
    command_module = ""
    for module in command_dictionary:
        if command in command_dictionary[module]:
            # print("here")
            command_module = module
    # print(command)
    # print(command_module)
    try:
        return SettingsController(message.guild).get_setting(command_module, command)
    except KeyError:
        return True
Exemple #6
0
class Settings(commands.Cog):
    def __init__(self, bot):
        self.client = bot
        self.functionMap = {"add": self.add, "update": self.update, "reset": self.reset, "get": self.get}
        self.controller = None
        self.jsonString = ""
        self.ctx = None

    def generate_controller(self, guild):
        self.controller = SettingsController(guild)

    def add(self):
        return self.controller.add(self.jsonString)

    def update(self):
        return self.controller.update(self.jsonString)

    def reset(self):
        return self.controller.remove(self.jsonString)

    def get(self):
        return "```\n" + self.controller.get() + "\n```"

    @commands.command()
    async def settings(self, ctx):
        if not ctx.message.author.top_role.permissions.administrator:
            return
        option = ctx.message.content.split()[1]
        self.ctx = ctx
        self.jsonString = " ".join(ctx.message.content.split()[2:])
        # print(option)
        # print(self.jsonString)
        self.generate_controller(ctx.guild)
        result = self.functionMap[option]()
        if result:
            await self.ctx.channel.send(result)
Exemple #7
0
async def react_to_msg(message, client):
    """
    Used to check message contents for keywords. Adds a specified reaction on a message.
    Full implementation in Reactions
    :param message: Discord.py Message class
    :param client: bot from commands.Bot
    :return: None
    """
    if not SettingsController(message.guild).get_setting("reactions", "react"):
        return
    try:

        reaction_controller = ReactionsController(client, message.guild)  # Create the controller
        # reaction_controller.react_dict.import_guild_reactions("reactions_pickle.txt") # if you need to import reacts
        dict_r = reaction_controller.get_dict()  # Get the dictionary
        for key in dict_r:
            if message.content.find(key) != -1:  # If the message is found in the text of the message add the reaction
                await message.add_reaction(client.get_emoji(dict_r[key]))
                return
    except Exception:
        print("Something went wrong")
Exemple #8
0
 def generate_controller(self, guild):
     self.controller = SettingsController(guild)