Ejemplo n.º 1
0
 async def set_welcome_image(self, ctx, *, images_link):
     """
     Set Welcome Image
     """
     _image_list = images_link.split(" ")
     if len(_image_list) > 10:
         ctx.reply("No More 10 Images")
         return
     i = 0
     guild_data = {}
     image_name = []
     for link in _image_list:
         i = i + 1
         url = requests.get(link)
         background = Image.open(BytesIO(url.content))
         width, height = background.size
         if width <= 1920 and height <= 972:
             await ctx.send("minimum 1920*972 resolution required")
             return
         background = background.resize((1920, 972))
         output = ImageOps.fit(background,
                               background.size,
                               centering=(0.5, 0.5))
         output.save("images/backgrounds/" + str(ctx.guild.id) + "_" +
                     str(i) + ".jpg")
         image_name.append(str(ctx.guild.id) + "_" + str(i) + ".jpg")
     data = misc.return_data(str(ctx.guild.id), WELCOME_FILE_PATH)
     image_data = data['welcome_images']
     if len(image_data) > 10:
         ctx.reply("No More 10 Images")
     data["last_update"] = str(ctx.auther.id)
     guild_data[str(ctx.guild.id)] = data
     misc.write_data(str(ctx.guild.id), WELCOME_FILE_PATH)
     await ctx.send("backgrounds images set successfully")
Ejemplo n.º 2
0
    async def set_join_self(self, ctx, role: discord.Role):
        """
        Set Role When member Join
        """
        guild_data = {}
        data = misc.return_data(str(ctx.guild.id), WELCOME_FILE_PATH)
        #guild Data
        guild_data[str(ctx.guild.id)] = data

        if discord.utils.get(ctx.guild.roles, id=role.id):
            guild_data[str(ctx.guild.id)]["self_role"] = role.id
            misc.write_data(guild_data, WELCOME_FILE_PATH)
        else:
            await ctx.send("{} Role Not Found".format(role))
Ejemplo n.º 3
0
    async def welcome_enable(self, ctx, status):
        """
        Enable/Disable welcome msg
        """
        guild_data = {}
        data = misc.return_data(str(ctx.guild.id), WELCOME_FILE_PATH)
        if str(status) == "on" or str(status) == "ON" or str(
                status) == "enable":
            data['enable'] = True
            # print(status)
        elif str(status) == "off" or str(status) == "OFF" or str(
                status) == "disable":
            data['enable'] = False

        else:
            await ctx.reply("Bro use on/off or enable/disable ")
            return  # print(status+"1")
        # print(data)
        guild_data[str(ctx.guild.id)] = data
        misc.write_data(guild_data, WELCOME_FILE_PATH)
        await ctx.reply("welcome status is set to  {}".format(status))
Ejemplo n.º 4
0
    async def set_self_message(self,ctx,unique,channel : discord.TextChannel = None ,*,msg):
        """
        Age
        Are You An Adult or a Kid? React with :boy: for Kid and :man: for Adult
        """
        # #channel  unique title | desc | emoji & role | emoji & role

        #breakpoint |

        if unique == "yes" or unique == 'Yes' or unique == 'YES':
            unique = unique
        elif unique == 'no' or unique == 'No' or unique == 'NO':
            unique = None 

        else:
            msg = unique + " " + msg
            unique = None
        
        split_msg = str(msg).split("|")

        msg = str(msg).split(':')

        #new welcome msg store in new_msg
      
        # grep title and description
        title = split_msg.pop(0)
        desc =  split_msg.pop(0)

        new_msg = []
        # print(msg)
        for i in desc.split(":"):
            if i == '':
                pass
            else:
                # check emoji or not if not that means msg 
                if discord.utils.get(ctx.guild.emojis,name=i):
                    emoji = discord.utils.get(ctx.guild.emojis,name=i)
                    new_msg.append(str(emoji))
                else:
                    new_msg.append(str(i))
        wel = ""
        for i in new_msg:
            wel = wel + i 
        
        # print(wel)
        # store emoji with role
        emoji_role_dict = {}

        # all emoji in this list
        emoji_list = []

        # insert emoji and role in dict
        for em_and_role in split_msg:
            em_and_role = em_and_role.split("%")
            emoji_list.append(em_and_role[0].strip())
            emoji_role_dict[em_and_role[0].strip()] = em_and_role[1].strip()
        
        # print(emoji_role_dict)
        send_emb = discord.Embed(
            title=title,
            description = wel,
            color = 0x00ff00
        )
        send_emb.set_thumbnail(url=ctx.guild.icon_url)
        send_msg = await channel.send(embed=send_emb)
        channel_id = channel.id
        for i in emoji_list:
            try:
                if discord.utils.get(ctx.guild.emojis,name=str(i).replace(":",'')):
                    i = discord.utils.get(ctx.guild.emojis,name=str(i).replace(":",''))
            except:
                if discord.utils.get(ctx.guild.emojis,name=i):
                    i = discord.utils.get(ctx.guild.emojis,name=i)
            await send_msg.add_reaction(i)
        mes_list = []
        self_role_list = []
        data = None
        if misc.return_data(str(ctx.guild.id),ROLE_FILE_PATH):
            data = misc.return_data(str(ctx.guild.id),ROLE_FILE_PATH)
            mes_list = data["message_id"]
            # self_role_list = data["self_role_list"]
        mes_list.append(send_msg.id)
        """format {
        guild_id  : {
            messeage_id :{
                reactionrole:{
                },
                unique: yes
            }
        }"""
        guild_data = {}
        data2 = {
                "message_id": mes_list,
                str(send_msg.id):{
                "reactionrole":emoji_role_dict,
                "unique": unique
            }
        }
        if data:
            guild_data[str(ctx.guild.id)] = {**data, **data2}
        else:
            # print("fdsg")
            guild_data[str(ctx.guild.id)] = {**data2}
        if misc.write_data(guild_data,ROLE_FILE_PATH):
            ctx.reply("role set successfully")
Ejemplo n.º 5
0
    async def on_raw_reaction_add(self, payload):
        reaction = str(payload.emoji)
        msg_id = payload.message_id
        ch_id = payload.channel_id
        username = payload.member
        user_id = payload.user_id
        guild_id = payload.guild_id
        """
        {
            guild.id : {
                member_list : [],
                member_id : []
                }
            }
        }
        """
        print(reaction)
        data = misc.return_data(str(guild_id), ROLE_FILE_PATH)

        if msg_id not in data["message_id"]:
            return

        # {
        #     member_list : [],
        #     member_id : []
        # }
        member_rols = []
        member_id_list = []
        member_data = misc.return_data(str(guild_id), MEMBER_ROLE_FILE_PATH)
        print(member_data)
        try:
            member_id_list = member_data['member_list']
            try:
                if str(user_id) in member_data["member_list"]:
                    member_rols = member_data[str(user_id)]
                else:
                    member_id_list.append(str(user_id))
                    pass
            except:
                pass
        except TypeError:
            member_id_list.append(str(user_id))
            pass

        print(member_rols, "roles")

        # if isinstance(unique,int):

        unique = "no"
        get_data = data[str(msg_id)]

        unique_status = get_data['unique']

        print(isinstance(unique_status, int))
        get_str = False
        if isinstance(unique_status, int):
            unique = unique_status
        else:
            get_str = True
            if str(unique_status).lower() == "yes":
                unique = 'yes'

        # if isinstance()
        emoji_role_dict = get_data["reactionrole"]
        channel = discord.utils.get(payload.member.guild.channels, id=ch_id)
        member = await payload.member.guild.fetch_member(user_id)

        dis_msg = await channel.fetch_message(int(msg_id))
        self_role_list = []
        member_rol_list = []
        for key, value in emoji_role_dict.items():
            self_role_list.append(
                int(str(value).replace("<@&", "").replace(">", '')))
            try:
                if discord.utils.get(payload.member.guild.emojis,
                                     name=str(key).replace(":", '')):
                    key = discord.utils.get(payload.member.guild.emojis,
                                            name=str(key).replace(":", ''))
            except:
                if discord.utils.get(payload.member.guild.emojis, name=key):
                    key = discord.utils.get(payload.member.guild.emojis,
                                            name=key)
            if str(key) == (reaction):

                member = await payload.member.guild.fetch_member(user_id)
                role = payload.member.guild.get_role(
                    int(str(value).replace("<@&", '').replace(">", '')))
                await member.add_roles(role)
                member_rols.append(str(role.id))
                write = {}

                # write[str(guild_id)] = {
                try:
                    temp_data = {
                        "member_list": member_id_list,
                        str(user_id): member_rols
                    }
                    member_data.update(temp_data)
                except:
                    member_data = {
                        "member_list": member_id_list,
                        str(user_id): member_rols
                    }
                write[str(guild_id)] = member_data
                misc.write_data(write, MEMBER_ROLE_FILE_PATH)
                channel = discord.utils.get(payload.member.guild.channels,
                                            id=ch_id)

            else:
                if get_str:
                    if unique.lower() == "yes":
                        await dis_msg.remove_reaction(key, member)

        member = await payload.member.guild.fetch_member(user_id)

        # try:
        if int(unique) < len(member_rols):
            ran_num = random.randint(0, (len(member_rols) - 1))
            # ran_num = 0
            print(ran_num)
            _reaction = str(list(emoji_role_dict.keys())[ran_num]).strip()
            print(_reaction)
            print(
                (str(emoji_role_dict[_reaction]).replace("<@&",
                                                         '').replace(">", '')))
            role = payload.member.guild.get_role(
                int(
                    str(emoji_role_dict[_reaction]).replace("<@&", '').replace(
                        ">", '')))
            print(role, role.id)
            member_rols.remove(str(role.id))
            write = {}
            write[str(guild_id)] = {
                "member_list": member_id_list,
                str(user_id): member_rols
            }
            misc.write_data(write, MEMBER_ROLE_FILE_PATH)
            print(
                discord.utils.get(payload.member.guild.emojis,
                                  name=str(_reaction).replace(":", '')))
            if discord.utils.get(payload.member.guild.emojis,
                                 name=str(_reaction).replace(":", '')):
                key = discord.utils.get(payload.member.guild.emojis,
                                        name=str(_reaction).replace(":", ''))
            else:
                print("exce")
                # if discord.utils.get(payload.member.guild.emojis,name=_reaction):
                # key = discord.utils.get(payload.member.guild.emojis,name=_reaction)
                key = _reaction

            print(key)
            await dis_msg.remove_reaction(key, member)