Example #1
0
    def mute_user(self, event, target, length: list = None):
        """
        ***The Mute Command***

        This command restrict the target's message permissions either forever, or a certain amount of time if specified.

        ***Required Values***
        > __target__ **The user's full discord name, mention, or ID**

        **Optional Values**
        > __length__ **The amount of time until unmute in discord format.
        """
        target.add_role(self.config["MUTE_ROLE"])
        event.msg.add_reaction("👍")
        if length:
            seconds = sum(length)
            self.spawn_later(seconds, self.unmute, target)
            self.log_action(
                "Muted",
                "Muted {t.mention} for {s} seconds. Moderator: {e.author.mention}",
                target,
                s=seconds,
                e=event)
            Mute.create(target=target.id, end_time=int(time() + seconds))
        else:
            Mute.create(
                target=target.id, end_time=time() *
                2)  # This should ensure they never get unmuted, in theory?
Example #2
0
 def unmute(self, member, force=False):
     unmute = True
     for mute in Mute.find(Mute.target == member.id):
         if mute.end_time <= time() or force:
             mute.delete_self()
         else:
             unmute = False
     if unmute:
         member.remove_role(self.config["MUTE_ROLE"])
         self.log_action("Unmute", "Unmuted {t.mention}", member.user)
Example #3
0
    def schedule_unmutes(self, _):
        mutes = Mute.find_all()
        unmutes = {}
        for mute in mutes:
            if time() >= mute.end_time:
                mute.delete_self()
                if mute.target not in unmutes:
                    unmutes[mute.target] = True,
            else:
                unmutes[mute.target] = False, int(mute.end_time - time())

        def remove_mute(user: int):
            self.client.api.guilds_members_roles_remove(
                self.config['GUILD_ID'], user, self.config["MUTE_ROLE"])
            return Mute.delete(Mute.target == user)

        for target, doit in unmutes.items():
            if doit[0]:
                self.client.api.guilds_members_roles_remove(
                    self.config['GUILD_ID'], target, self.config["MUTE_ROLE"])
            else:
                self.spawn_later(doit[1], remove_mute, target)
Example #4
0
 def execute_action(self, member, action):
     if "mute" in action:
         member.add_role(self.config["MUTE_ROLE"])
         self.spawn_later(action['mute'], self.unmute, member)
         Mute.create(target=member.id,
                     end_time=int(time() + action['mute']))
Example #5
0
 def remove_mute(user: int):
     self.client.api.guilds_members_roles_remove(
         self.config['GUILD_ID'], user, self.config["MUTE_ROLE"])
     return Mute.delete(Mute.target == user)