Example #1
0
    async def postauto(self, ctx, lov):
        """
        Sender en melding som automatisk oppdateres når reglene oppdateres.
        """
        rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)
        rule_text = rules.get_rule_text(lov)

        if rule_text is None:
            await ctx.send('Sjekk at reglene finnes.\n' +
                           '**Liste over lovene i lovherket:**\n' +
                           f'{rules.get_rules_formatted()}')
            return

        if rule_text == "":
            await ctx.send("Den regelen er helt tom.")
            return

        msg = await ctx.send(rule_text)
        added = rules.add_link_setting('auto_update',
                                       lov,
                                       f'{self._format_message_link(msg)}')

        conf_msg = await ctx.send("Meldingen oppdateres nå automatisk")
        await asyncio.sleep(5)
        await conf_msg.delete()
Example #2
0
    async def on_message(self, message):

        if message.author.id == self.bot.user.id:
            return

        if not isinstance(message.channel, discord.TextChannel):
            return

        content = message.content

        if content is '' or content[0] is not "§":  # hardcoded atm
            return

        split = content.split('§')
        num = split[1]

        if num is '':
            return

        # crap way to avoid running when a command runs
        try:
            int(num.split()[0])
        except:
            return

        rules = RuleManager(message.guild.id, self.SERVERS_PATH)

        lov = rules.get_settings("default_rule")
        rule_text = rules.get_rule_text(lov)

        context = message.channel

        if rule_text is None:
            await context.send('**Du må sette default før dette fungerer\n' +
                               'Liste over lovene i lovherket:**\n' +
                               f'{rules.get_rules_formatted()}')
            return

        if rule_text == "":
            await context.send("Denne regelen er helt tom.")
            return

        # Get only specified rules
        partial_rules = ""
        no_dupes = remove_duplicates(num.split())
        for rule in no_dupes:
            ruleregex = r"(§ *" + re.escape(rule) + r"[a-z]?: [\S ]*)"
            m = re.search(ruleregex, rule_text)
            if m is not None:
                partial_rules += m.groups()[0] + "\n"

        if partial_rules is '':
            return
        await context.send(partial_rules)
Example #3
0
 async def show_alternate(self, ctx, lov: str=None):
     """
     Viser reaksjons-regler fra lovherket.
     """
     rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)
     rule_text = rules.get_rule_text(lov, alternate=True)
     if rule_text is not None:
         await ctx.send("```\n" + rule_text + "\n```")
     else:
         await ctx.send('**Liste over react-regler i lovherket:**\n' +
                        f'{rules.get_rules_formatted(alternate=True)}')
Example #4
0
    async def plaintext(self, ctx, lov):
        """
        Sender reglene så de enkelt kan kopieres med formatering.
        """
        rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)
        rule_text = rules.get_rule_text(lov)

        if rule_text is None:
            await ctx.send("Sjekk at du skrev riktig.")
        else:
            await ctx.send("```\n" + rule_text + "\n```")
Example #5
0
    async def rules(self, ctx,
                    lov: typing.Union[int, str]=None, *, num: str=None):
        """
        Se reglene i lovherket.
        """

        rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)

        if isinstance(lov, int):
            if num is None:
                num = str(lov)
            else:
                num = str(lov) + " " + num
            lov = rules.get_settings("default_rule")

        rule_text, date = rules.get_rule_text(lov)

        if rule_text is None:
            await ctx.send('**Liste over lovene i lovherket:**\n' +
                           f'{rules.get_rules_formatted()}')
            return

        if rule_text == "":
            await ctx.send("Denne regelen er helt tom.")
            return

        # Get only specified rules
        if num is not None:
            await ctx.message.delete()
            partial_rules = ""

            no_dupes = remove_duplicates(num.split())

            for rule in no_dupes:
                ruleregex = r"(§ *" + re.escape(rule) + r"[a-z]?: [\S ]*)"
                m = re.search(ruleregex, rule_text)
                if m is not None:
                    partial_rules += m.groups()[0] + "\n"

            if partial_rules == "":
                await ctx.send(f'Fant ikke reglene du ser etter')
            else:
                if lov != rules.get_settings("default_rule"):
                    partial_rules = f'**I reglene for {lov}:**\n' \
                        + partial_rules
                await ctx.send(partial_rules)
        else:
            embed = await self._create_embed(rule_text, date)
            await ctx.send(embed=embed)
Example #6
0
    async def set_default_rule(self, ctx, lov):
        """
        Setter default regler.
        """
        rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)
        rule_text = rules.get_rule_text(lov)

        if rule_text is None:
            await ctx.send(f'Den regelen er ikke i lovherket.\n\n' +
                            '**Liste over lovene i lovherket:**\n' +
                            f'{rules.get_rules_formatted()}')
            return

        rules.change_setting("default_rule", lov.lower())
        await ctx.send(f'{lov} er nå serverens default regel')
Example #7
0
    async def _dm_rules(self, user, msg):

        rules = RuleManager(msg.guild.id, self.SERVERS_PATH)
        react_rules = rules.get_settings("react_rules")
        msg_link = self._format_message_link(msg)
        rule_name = None
        for rule in react_rules:
            if rule["link"] == msg_link:
                rule_name = rule["name"]

        if rule_name is None:
            return

        rule_text = rules.get_rule_text(rule_name, alternate=True)
        try:
            await user.send(rule_text)
        except discord.Forbidden:
            await msg.channel.send(f"I can't send you messages {user.mention}")
Example #8
0
    async def _update_messages(self, ctx, name=None):
        rules = RuleManager(ctx.guild.id, self.SERVERS_PATH)
        auto_update_messages = rules.get_settings('auto_update')

        for message in auto_update_messages:
            if message["name"] == name or name is None:
                msg = await self._get_linked_message(ctx, message["link"])
                if msg is None:
                    await ctx.send('Klarer ikke finne følgende melding:\n' +
                                   f'{message["link"]}\nSjekk om den finnes,' +
                                   ' hvis ikke fjern den med `§auto fjern`')
                    continue

                updated_text = rules.get_rule_text(message["name"])
                if updated_text is None:
                    await ctx.send('Fant ikke en regel med følgende navn:\n' +
                                   f'{message["name"]}.')
                    continue

                await asyncio.sleep(2)
                await msg.edit(content=updated_text)