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")
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))
async def show_prefix(self, ctx, *, msg=None): """ Show The Sets Prefix to The Server """ data = misc.return_data(str(ctx.guild.id), PREFIX_FILE_PATH) guild = ctx.guild.id try: if type(data) == type(str("d")): await ctx.reply("The prefix for the {} is '' **{}** ''".format( ctx.guild.name, data)) else: pre = ",".join(data) # pre = " " # for i in data: # pre = i + " ," + pre await ctx.reply( "The prefixes for the {} is '' **{}** ''".format( str(ctx.guild.name), pre)) except Exception as e: print(e)
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))
async def get_welcome(self, ctx): """ Get Welcome Message status """ data = misc.return_data(str(ctx.guild.id), WELCOME_FILE_PATH) role = discord.utils.get(ctx.guild.roles, id=data["self_role"]) # print(role ) w_channel = discord.utils.get(ctx.guild.channels, id=data["welcome_channel"]) welcome_msg = data["welcome_msg"] args = data['args'] # w_channel = data['welcome_channel'] enable = data['enable'] # for arg in args: # welcome_msg = welcome_msg.replace("{}","{"+arg+"}").replace("\n","") w_data = dict( enable=enable, welcome_msg=welcome_msg, welcome_channel=w_channel, self_role=role, ) # print(type(welcome_msg),welcome_msg) # welcome_msg = ["fsdf \n\n","\nfsgegs"] # await ctx.send(welcome_msg) embed = discord.Embed(title="Welcome msg", colour=0x00ff00, description="".join(welcome_msg)) # print(welcome_msg) # embed.set_image(url='attachment://tmpBv.png') # file = discord.File(open('tmpBv.png', 'rb')) embed.add_field(name="is_enable", value=enable, inline=False) # embed.add_field(name="welcome_message",value="".join(welcome_msg),inline=True) embed.add_field(name="welcome_channel", value=w_channel, inline=True) embed.add_field(name="self_role", value=role, inline=False) await ctx.send(embed=embed)
async def on_raw_reaction_remove(self, payload): reaction = str(payload.emoji) msg_id = payload.message_id user_id = payload.user_id guild_id = payload.guild_id guild_name = self.bot.get_guild(guild_id) member_name = guild_name.get_member(user_id) data = misc.return_data(str(guild_id), ROLE_FILE_PATH) if msg_id not in data["message_id"]: return get_data = data[str(msg_id)] emoji_role_dict = get_data["reactionrole"] for key, value in emoji_role_dict.items(): try: if discord.utils.get(guild_name.emojis, name=str(key).replace(":", '')): key = discord.utils.get(guild_name.emojis, name=str(key).replace(":", '')) except: if discord.utils.get(guild_name.emojis, name=key): key = discord.utils.get(guild_name.emojis, name=key) try: # ifreaction is in form of <:name:id> if str(key.id) == str(reaction.split(":")[2].replace(">", '')): role = guild_name.get_role( int(str(value).replace("<@&", '').replace(">", ''))) await member_name.remove_roles(role) except: # if reaction is default emoji if str(key) == reaction: role = guild_name.get_role( int(str(value).replace("<@&", '').replace(">", ''))) await member_name.remove_roles(role)
async def hl(self, ctx, *cmd): """Send bot help msg Args: {prefix} help command """ # print(misc.return_data(str(ctx.guild.name),PREFIX_FILE_PATH)) prefix_data = misc.return_data(str(ctx.guild.id), PREFIX_FILE_PATH) prefixes = ",".join(prefix_data) # for i in prefix_data: # prefixes = i + ","+prefixes if len(prefix_data) < 2: prefix = prefix_data else: prefix = prefix_data[1] embed = discord.Embed( color=ctx.author.color, description="Use `{0}help <commands or modules>` to know what I do " .format(prefix)) embed.set_author(icon_url=self.bot.user.avatar_url, name=self.bot.user) embed.set_thumbnail(url=self.bot.user.avatar_url) if not cmd: embed.add_field(name="Prefixes", value="Current Prefixes for {0} is `{1}`".format( str(ctx.guild.name), prefixes), inline=False) cogs_description = "" for cog in self.bot.cogs: # print(str(cog)) if "BotEvent" in str(cog): pass else: # cogs_description += "`{0}` {1}\n".format(cog,self.bot.cogs[cog].__doc__) embed.add_field(name=cog, value=self.bot.cogs[cog].__doc__, inline=True) elif len(cmd) == 1: for cog in self.bot.cogs: # print(cog.lower()) # print(cmd[0].lower()) if cmd[0].lower() == cog.lower(): embed.add_field(name="{0} - Commands ".format(cog), value=self.bot.cogs[cog].__doc__, inline=False) for command in self.bot.get_cog(cog).get_commands(): if not command.hidden: embed.add_field(name="`{0}{1}`".format( prefix, command.name), value=command.help, inline=True) break for cog in self.bot.cogs: for commands in self.bot.get_cog(cog).get_commands(): # print(commands,cmd) if cmd[0].lower() == str(commands).lower(): embed.add_field(name="`{0}{1} `".format( prefix, cmd[0]), value=help.return_help(str(cmd[0]))) # break # embed = discord.Embed(title="{}") # footer embed.add_field(name="Join Our Community For More Help", value="[Community](https://discord.gg/SgV5yhzy)", inline=False) # embed.set_footer(text="https://discord.gg/SgV5yhzy",) await ctx.send(embed=embed)
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")
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)
async def on_member_join(self, member): member_id = member.id member_name = member.name member_tag = "<@" + str(member_id) + ">" data = misc.return_data(str(member.guild.id), WELCOME_FILE_PATH) role = discord.utils.get(member.guild.roles, id=data["self_role"]) w_channel = discord.utils.get(member.guild.channels, id=data["welcome_channel"]) welcome_msg = data["welcome_msg"] is_w_images = False count_list = [] for i in range(10): if os.path.isfile( os.path.join( ROOT_PATH, "images/backgrounds/" + str(member.guild.id) + "_" + str(i) + ".jpg")): is_w_images = True count_list.append(i) else: pass try: image_num = random.choice(count_list) except: image_num = random.randint(1, 10) W, H = 1920, 872 # messeges hello = "Hey Buddy," username = str(self.bot.get_user(member.id)) msg = 'You Are {}th Member of The Server'.format( member.guild.member_count) url = requests.get(member.avatar_url) avatar = Image.open(BytesIO(url.content)) avatar = avatar.resize((380, 380)) bigsize = (avatar.size[0] * 3, avatar.size[1] * 3) mask = Image.new('L', bigsize, 0) draw = ImageDraw.Draw(mask) draw.ellipse((0, 0) + bigsize, fill=255) mask = mask.resize(avatar.size) avatar.putalpha(mask) output = ImageOps.fit(avatar, mask.size, centering=(0.5, 0.5)) output.putalpha(mask) output.save('images/avatar.png') ava = Image.open('images/avatar.png') ava_draw = ImageDraw.Draw(ava) ava_draw.arc((0, 0, 380, 380), start=0, end=360, fill=(194, 83, 111), width=12) ava.save("images/avatar.png") # avatar = Image.open('avatar2.png') if is_w_images: welc = Image.open('images/backgrounds/' + str(member.guild.id) + "_" + str(image_num) + '.jpg') else: welc = Image.open('images/backgrounds/welcome' + str(image_num) + '.jpg') font1 = ImageFont.truetype('fonts/UbuntuMono-B.ttf', 90) font2 = ImageFont.truetype('fonts/Caveat-Bold.ttf', 100) welc_draw = ImageDraw.Draw(welc) hello_w, hello_h = welc_draw.textsize(hello, font2) user_w, user_h = welc_draw.textsize(username, font1) msg_w, msg_h = welc_draw.textsize(msg, font2) welc_draw.text(xy=((W - hello_w) / 2, (H - hello_h) / 1.44), text=hello, fill=(190, 222, 203), font=font2, align='center') welc_draw.text(xy=((W - user_w) / 2, (H - user_h) / 1.2), text=username, fill=(222, 239, 90), font=font1, align='center') welc_draw.text(xy=((W - msg_w) / 2, (H - msg_h) / 1), text=msg, fill=(248, 206, 160), font=font2, align='center') welc.paste(ava, (760, 150), ava) test = [] for i in welcome_msg: wlmsg = i if "member.mention" in i: wlmsg = str(i).replace("{" + "member.mention" + "}", str(member_tag)) if "member.name" in i: wlmsg = str(i).replace("{" + "member.name" + "}", str(member_name)) if "member.count" in i: wlmsg = str(i).replace("{" + "member.count" + "}", str(member.guild.member_count)) if "member.server_name" in i: wlmsg = str(i).replace("{" + "member.server_name" + "}", str(member.guild.name)) if "member.role" in i: wlmsg = str(i).replace("{" + "member.role" + "}", str(role)) else: test.append(wlmsg) welc.save('tmpBv.png', format='PNG') # bot. if role: await member.add_roles(role) file = discord.File(open('tmpBv.png', 'rb')) # embed = discord.Embed(title=':r_arrow: Hey buddy {}'.format(str(member)), description='welcome to the {}! you are {}th member of no server.'.format(member.guild.name, member.guild.member_count), color=0x1f1d1d) embed = discord.Embed(description=''.join(test), color=0x00ff00) # embed.set_thumbnail(url = member.guild.icon_url) embed.set_image(url='attachment://tmpBv.png') await w_channel.send(file=file, embed=embed)
async def set_welcome_message(self, ctx, set_channel: discord.TextChannel = None, *, msg=None): """ Set Welcome Message """ if msg is None: msg = "" msg = str(msg).split(':') #new welcome msg store in new_msg new_msg = [] # print(msg) for i in msg: 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 = "" #replace new line for i in new_msg: wel = wel + i wel = wel.replace('\n', "\n\ncers").split("\ncers") # roles = None # server_id guild_id = ctx.guild.id # check author is server owner or not # if ctx.guild.owner_id != ctx.author.id: # await ctx.send("Bro you are not owner of this server so you cant set welcome msg") # get Welcome data for the server data = misc.return_data(str(guild_id), WELCOME_FILE_PATH) # Check welcome channel exist or not if discord.utils.get(self.bot.get_all_channels(), guild__name=ctx.guild.name, id=set_channel.id): channel_id = set_channel.id else: #get welcome channel channel_id = data["welcome_channel"] # if self_role with open(WELCOME_FILE_PATH, 'r') as f: msg_data = json.load(f) msg_data[str(ctx.guild.id)]["welcome_channel"] = channel_id msg_data[str(ctx.guild.id)]["welcome_msg"] = wel with open(WELCOME_FILE_PATH, 'w') as f: json.dump(msg_data, f, indent=4) await ctx.send("welcome msg set successfully")
async def test_welcome(self, ctx): """ Send Original Set Msg """ member_id = ctx.author.id member_name = ctx.author.name + "#" + ctx.author.discriminator member_tag = "<@" + str(member_id) + ">" data = misc.return_data(str(ctx.guild.id), WELCOME_FILE_PATH) role = discord.utils.get(ctx.guild.roles, id=data["self_role"]) # print(role ) w_channel = discord.utils.get(ctx.guild.channels, id=data["welcome_channel"]) welcome_msg = data["welcome_msg"] server_name = data["server_name"] # print(server_name) args = data['args'] # w_channel = data['welcome_channel'] enable = data['enable'] # for arg in args: # welcome_msg = welcome_msg.replace("{}","{"+arg+"}").replace("\n","") w_data = dict( enable=enable, welcome_msg=welcome_msg, welcome_channel=w_channel, self_role=role, ) # print(type(welcome_msg),welcome_msg) # welcome_msg = ["fsdf \n\n","\nfsgegs"] # await ctx.send(welcome_msg) test = [] for i in welcome_msg: # tags = re.findall("{{(.*)}}") wlmsg = i if "member.mention" in i: wlmsg = str(i).replace("{" + "member.mention" + "}", member_tag) # test.append(wlmsg) if "member.name" in i: wlmsg = str(i).replace("{" + "member.name" + "}", member_name) # test.append(wlmsg) if "member.count" in i: wlmsg = str(i).replace("{" + "member.count" + "}", str(ctx.guild.member_count)) # test.append(wlmsg) if "member.server_name" in i: wlmsg = str(i).replace("{" + "member.server_name" + "}", str(ctx.guild.name)) # test.append(wlmsg) if "member.role" in i: wlmsg = str(i).replace("{" + "member.role" + "}", str(role.mention)) # test.append(wlmsg) test.append(wlmsg) # else: # test.append(i) # if os.path.isfile(os.path.join(ROOT_PATH,"images/backgrounds/"+str(ctx.guild.id)+"_1.jpg")): # is_w_images = True # else: embed = discord.Embed( # # title = "Welcome msg", colour=0x00ff00, # description= "".join(welcome_msg) ) is_w_images = False count_list = [] for i in range(10): if os.path.isfile( os.path.join( ROOT_PATH, "images/backgrounds/" + str(ctx.guild.id) + "_" + str(i) + ".jpg")): is_w_images = True count_list.append(i) else: pass # print(count_list) try: image_num = choice(count_list) # print(image_num,is_w_images) except: image_num = randint(1, 10) W, H = 1920, 872 # messeges hello = "Hey Buddy," username = str(self.bot.get_user(ctx.author.id)) msg = 'You Are {}th Member of The Server'.format( ctx.guild.member_count) url = requests.get(ctx.author.avatar_url) avatar = Image.open(BytesIO(url.content)) avatar = avatar.resize((380, 380)) bigsize = (avatar.size[0] * 3, avatar.size[1] * 3) mask = Image.new('L', bigsize, 0) draw = ImageDraw.Draw(mask) draw.ellipse((0, 0) + bigsize, fill=255) mask = mask.resize(avatar.size) avatar.putalpha(mask) output = ImageOps.fit(avatar, mask.size, centering=(0.5, 0.5)) output.putalpha(mask) output.save('images/avatar.png') ava = Image.open('images/avatar.png') ava_draw = ImageDraw.Draw(ava) ava_draw.arc((0, 0, 380, 380), start=0, end=360, fill=(194, 83, 111), width=12) ava.save("images/avatar.png") if is_w_images: welc = Image.open('images/backgrounds/' + str(ctx.guild.id) + "_" + str(image_num) + '.jpg') else: welc = Image.open('images/backgrounds/welcome' + str(image_num) + '.jpg') font1 = ImageFont.truetype('fonts/UbuntuMono-B.ttf', 90) font2 = ImageFont.truetype('fonts/Caveat-Bold.ttf', 100) welc_draw = ImageDraw.Draw(welc) hello_w, hello_h = welc_draw.textsize(hello, font2) user_w, user_h = welc_draw.textsize(username, font1) msg_w, msg_h = welc_draw.textsize(msg, font2) welc_draw.text(xy=((W - hello_w) / 2, (H - hello_h) / 1.44), text=hello, fill=(190, 222, 203), font=font2, align='center') welc_draw.text(xy=((W - user_w) / 2, (H - user_h) / 1.2), text=username, fill=(222, 239, 90), font=font1, align='center') welc_draw.text(xy=((W - msg_w) / 2, (H - msg_h) / 1), text=msg, fill=(248, 206, 160), font=font2, align='center') welc.paste(ava, (760, 150), ava) welc.save('tmpBv.png', format='PNG') # print(test) embed = discord.Embed( # title = "Welcome msg", colour=0x00ff00, description="".join(test)) file = discord.File(open("tmpBv.png", 'rb')) embed.set_image(url='attachment://tmpBv.png') await ctx.send(embed=embed, file=file)