コード例 #1
0
ファイル: utility.py プロジェクト: FunnyBunnyKeK/Selfbot
 async def delete(self, ctx, txt: str = None, channel: str = None):
     """Deletes the last message sent or n messages sent. Ex: >d 5"""
     if txt:  # If number of seconds/messages are specified
         await self.bot.delete_message(ctx.message)
         deleted = 0
         if txt == "all": limit = 1000
         else:
             txt = int(txt)
             limit = 200
             if txt > 200: txt = 200
         if channel:
             channel = find_channel(ctx.message.server.channels, channel)
             if not channel:
                 channel = find_channel(self.bot.get_all_channels(),
                                        channel)
         else:
             channel = ctx.message.channel
         async for sent_message in self.bot.logs_from(channel, limit=limit):
             if sent_message.author == ctx.message.author:
                 try:
                     await self.bot.delete_message(sent_message)
                     deleted += 1
                 except:
                     pass
                 if deleted == txt: break
     else:  # If no number specified, delete last message immediately
         await self.bot.delete_message(
             self.bot.self_log[ctx.message.channel.id].pop())
         await self.bot.delete_message(
             self.bot.self_log[ctx.message.channel.id].pop())
コード例 #2
0
    async def react(self,
                    ctx,
                    msg: str,
                    msg_id="last",
                    channel="current",
                    prefer_combine: bool = False):
        """Add letter(s) as reaction to previous message. Ex: >react hot"""
        await ctx.message.delete()
        msg = msg.lower()

        msg_id = None if not msg_id.isdigit() else int(msg_id)

        limit = 25 if msg_id else 1

        reactions = []
        non_unicode_emoji_list = []
        react_me = ""  # this is the string that will hold all our unicode converted characters from msg

        # replace all custom server emoji <:emoji:123456789> with "<" and add emoji ids to non_unicode_emoji_list
        char_index = 0
        while char_index < len(msg):
            react_me += msg[char_index]
            if msg[char_index] == '<':
                if (char_index != len(msg) - 1) and msg[char_index + 1] == ":":
                    name_end_colon = msg[char_index +
                                         2:].index(':') + char_index
                    id_end = msg[name_end_colon +
                                 2:].index('>') + name_end_colon
                    non_unicode_emoji_list.append(
                        msg[name_end_colon + 3:id_end + 2]
                    )  # we add the custom emoji to the list to replace '<' later
                    char_index = id_end + 2  # jump ahead in react_me parse
                else:
                    await ctx.send(self.bot.bot_prefix +
                                   "Can't react with '<'.")
            char_index += 1
        if Fun.has_dupe(non_unicode_emoji_list):
            return await ctx.send(
                self.bot.bot_prefix +
                "You requested that I react with at least two of the exact same specific emoji. I'll try to find alternatives for alphanumeric text, but if you specify a specific emoji must be used, I can't help."
            )

        react_me_original = react_me  # we'll go back to this version of react_me if prefer_combine is false but we can't make the reaction happen unless we combine anyway.

        if Fun.has_dupe(
                react_me
        ):  # there's a duplicate letter somewhere, so let's go ahead try to fix it.
            if prefer_combine:  # we want a smaller reaction string, so we'll try to combine anything we can right away
                react_me = Fun.replace_combos(react_me)
            react_me = Fun.replace_letters(react_me)

            if Fun.has_dupe(
                    react_me):  # check if we were able to solve the dupe
                if not prefer_combine:  # we wanted the most legible reaction string possible, even if it was longer, but unfortunately that's not possible, so we're going to combine first anyway
                    react_me = react_me_original
                    react_me = Fun.replace_combos(react_me)
                    react_me = Fun.replace_letters(react_me)
                    if Fun.has_dupe(
                            react_me
                    ):  # this failed too, so there's really nothing we can do anymore.
                        return await ctx.send(
                            self.bot.bot_prefix +
                            "Failed to fix all duplicates. Cannot react with this string."
                        )
                else:
                    return await ctx.send(
                        self.bot.bot_prefix +
                        "Failed to fix all duplicates. Cannot react with this string."
                    )

            lt_count = 0
            for char in react_me:
                if char != "<":
                    if char not in "0123456789":  # these unicode characters are weird and actually more than one character.
                        if char != '⃣':  # </3
                            reactions.append(char)
                    else:
                        reactions.append(self.emoji_dict[char][0])
                else:
                    reactions.append(
                        discord.utils.get(
                            self.bot.emojis,
                            id=int(non_unicode_emoji_list[lt_count])))
                    lt_count += 1
        else:  # probably doesn't matter, but by treating the case without dupes seperately, we can save some time
            lt_count = 0
            for char in react_me:
                if char != "<":
                    if char in "abcdefghijklmnopqrstuvwxyz0123456789!?":
                        reactions.append(self.emoji_dict[char][0])
                    else:
                        reactions.append(char)
                else:
                    reactions.append(
                        discord.utils.get(
                            self.bot.emojis,
                            id=int(non_unicode_emoji_list[lt_count])))
                    lt_count += 1

        if channel == "current":
            async for message in ctx.message.channel.history(limit=limit):
                if (not msg_id
                        and message.id != ctx.message.id) or (msg_id
                                                              == message.id):
                    for i in reactions:
                        try:
                            await message.add_reaction(i)
                        # :ok_hand: lit fam :ok_hand:
                        except:
                            pass
        else:
            found_channel = find_channel(ctx.guild.channels, channel)
            if not found_channel:
                found_channel = find_channel(self.bot.get_all_channels(),
                                             channel)
            if found_channel:
                async for message in found_channel.history(limit=limit):
                    if (not msg_id and message.id != ctx.message.id) or (
                            msg_id == message.id):
                        for i in reactions:
                            try:
                                await message.add_reaction(i)
                            except:
                                pass
            else:
                await ctx.send(self.bot.bot_prefix + "Channel not found.")
コード例 #3
0
ファイル: fun.py プロジェクト: Fragzowns/Discord-Selfbot
    async def react(self, ctx, msg: str, msg_id="last", channel="current", prefer_combine: bool = False):
        """Add letter(s) as reaction to previous message. Ex: [p]react hot"""
        await ctx.message.delete()
        msg = msg.lower()

        msg_id = None if not msg_id.isdigit() else int(msg_id)

        limit = 25 if msg_id else 1

        reactions = []
        non_unicode_emoji_list = []
        react_me = ""  # this is the string that will hold all our unicode converted characters from msg

        # replace all custom server emoji <:emoji:123456789> with "<" and add emoji ids to non_unicode_emoji_list
        char_index = 0
        emotes = re.findall(r"<a?:(?:[a-zA-Z0-9]+?):(?:[0-9]+?)>", msg)
        react_me = re.sub(r"<a?:([a-zA-Z0-9]+?):([0-9]+?)>", "", msg)
        
        for emote in emotes:
            reactions.append(discord.utils.get(self.bot.emojis, id=int(emote.split(":")[-1][:-1])))
            non_unicode_emoji_list.append(emote)
            
        
        if Fun.has_dupe(non_unicode_emoji_list):
            return await ctx.send(self.bot.bot_prefix + 
                                  "You requested that I react with at least two of the exact same specific emoji. I'll try to find alternatives for alphanumeric text, but if you specify a specific emoji must be used, I can't help.")

        react_me_original = react_me  # we'll go back to this version of react_me if prefer_combine is false but we can't make the reaction happen unless we combine anyway.

        if Fun.has_dupe(react_me):  # there's a duplicate letter somewhere, so let's go ahead try to fix it.
            if prefer_combine:  # we want a smaller reaction string, so we'll try to combine anything we can right away
                react_me = Fun.replace_combos(react_me)
            react_me = Fun.replace_letters(react_me)
            print(react_me)
            if Fun.has_dupe(react_me):  # check if we were able to solve the dupe
                if not prefer_combine:  # we wanted the most legible reaction string possible, even if it was longer, but unfortunately that's not possible, so we're going to combine first anyway
                    react_me = react_me_original
                    react_me = Fun.replace_combos(react_me)
                    react_me = Fun.replace_letters(react_me)
                    if Fun.has_dupe(react_me):  # this failed too, so there's really nothing we can do anymore.
                        return await ctx.send(self.bot.bot_prefix + "Failed to fix all duplicates. Cannot react with this string.")
                else:
                    return await ctx.send(self.bot.bot_prefix + "Failed to fix all duplicates. Cannot react with this string.")
                    

            lt_count = 0
            for char in react_me:
                if char not in "0123456789":  # these unicode characters are weird and actually more than one character.
                    if char != '⃣':  # </3
                        reactions.append(char)
                else:
                    reactions.append(self.emoji_dict[char][0])
        else:  # probably doesn't matter, but by treating the case without dupes seperately, we can save some time
            lt_count = 0
            for char in react_me:
                if char in "abcdefghijklmnopqrstuvwxyz0123456789!?":
                    reactions.append(self.emoji_dict[char][0])
                else:
                    reactions.append(char)

        if channel == "current":
            async for message in ctx.message.channel.history(limit=limit):
                if (not msg_id and message.id != ctx.message.id) or (msg_id == message.id):
                    for i in reactions:
                        try:
                            await message.add_reaction(i)
                        # :ok_hand: lit fam :ok_hand:
                        except:
                            pass
        else:
            found_channel = find_channel(ctx.guild.channels, channel)
            if not found_channel:
                found_channel = find_channel(self.bot.get_all_channels(), channel)
            if found_channel:
                async for message in found_channel.history(limit=limit):
                    if (not msg_id and message.id != ctx.message.id) or (msg_id == message.id):
                        for i in reactions:
                            try:
                                await message.add_reaction(i)
                            except:
                                pass
            else:
                await ctx.send(self.bot.bot_prefix + "Channel not found.")