async def nowplaying(cmd, message, args): if message.guild.id not in cmd.music.currents: embed = discord.Embed(color=0x0099FF, title='ℹ No Currently Playing Item') await message.channel.send(None, embed=embed) return item = cmd.music.currents[message.guild.id] sound = item['sound'] embed = discord.Embed(color=0x0099FF) embed.set_footer( text='You can click the author to go to the song\'s page.') if item['type'] == 0: embed.add_field(name='🎵 Now Playing', value=sound.title) embed.set_thumbnail(url=sound.thumb) embed.set_author( name=f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) embed.set_footer(text=f'Duration: {sound.duration}') elif item['type'] == 1: embed.add_field(name='🎵 Now Playing', value=sound['title']) embed.set_thumbnail(url=sound['artwork_url']) embed.set_author( name=f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) await message.channel.send(None, embed=embed)
async def reminder_clockwork(ev): while True: reminders = ev.db.find('Reminders', {}) for reminder in reminders: current_stamp = arrow.utcnow().timestamp execution_stamp = reminder['ExecutionStamp'] if current_stamp > execution_stamp: ev.db.delete_one('Reminders', {'ReminderID': reminder['ReminderID']}) channel = discord.utils.find(lambda x: x.id == reminder['ChannelID'], ev.bot.get_all_channels()) author = discord.utils.find(lambda x: x.id == reminder['UserID'], ev.bot.get_all_members()) if channel: target = channel elif author: target = author else: target = None if target: response = discord.Embed(color=0x1ABC9C, timestamp=arrow.get(reminder['CreationStamp']).datetime) if author: response.set_author(name=author.name, icon_url=user_avatar(author)) response.add_field(name='⏰ Reminder Message', value=f"```\n{reminder['TextMessage']}\n```") try: if author: await target.send(author.mention, embed=response) else: await target.send(embed=response) except: pass await asyncio.sleep(1)
async def impersonate(cmd, message, args): if args: if message.mentions: target = message.mentions[0] else: target = discord.utils.find( lambda x: x.name.lower() == ' '.join(args).lower(), message.server.members) if target: destination = f'chains/chain_{target.id}.yml' if os.path.exists(destination): with open(destination) as chain_file: chain_data = yaml.safe_load(chain_file) total_string = ' '.join(chain_data) chain = markovify.Text(total_string) sentence = chain.make_sentence(tries=100) if not sentence: response = discord.Embed( color=0xDB0000, title='😖 I Couldn\'t think of anything...') else: print(sentence) sentence = ftfy.fix_text(sentence) response = discord.Embed(color=0x1ABC9C) response.set_author(name=target.name, icon_url=user_avatar(target)) response.add_field(name='🤔 Something like...', value=f'```\n{sentence}\n```') else: response = discord.Embed(color=0x696969) response.add_field( name=f'🔍 Chain File Not Found For {target.name}', value=f'You can make one with `{Prefix}collectchain`!') await cmd.bot.send_message(message.channel, None, embed=response)
def update_details(db, server=None, user=None): if server: location = 'ServerList' exists = db[location].find_one({'ServerID': server.id}) updatetarget = {'ServerID': server.id} data = { 'ServerID': server.id, 'Icon': server.icon_url, 'ServerName': server.name, 'Owner': server.owner.name, 'OwnerID': server.owner.id } elif user: location = 'UserList' exists = db[location].find_one({'UserID': user.id}) updatetarget = {'UserID': user.id} user_ava = user_avatar(user) data = { 'UserID': user.id, 'UserName': user.name, 'Avatar': user_ava, 'Discriminator': user.discriminator } else: raise TypeError updatedata = {'$set': data} if exists: db[location].update_one(updatetarget, updatedata) else: db[location].insert_one(data)
async def reminders(cmd, message, args): all_reminders = cmd.db.find('Reminders', {'UserID': message.author.id}) reminder_list = [] for reminder in all_reminders: reminder_list.append(reminder) rem_count = len(reminder_list) if rem_count != 0: if args: choice = reminder_list[int(args[0])] creation_stamp = arrow.get(choice['CreationStamp']) creation_human = creation_stamp.humanize(arrow.utcnow()) creation_date = creation_stamp.format('YYYY-MM-DD HH:mm:ss') execution_stamp = arrow.get(choice['ExecutionStamp']) execution_human = execution_stamp.humanize(arrow.utcnow()) execution_date = execution_stamp.format('YYYY-MM-DD HH:mm:ss') response = discord.Embed(color=0x696969) response.set_author(name='🕙 Reminder Information', icon_url=user_avatar(message.author)) response.add_field(name='Created', value=f'{creation_human.title()}\n{creation_date} UTC', inline=True) response.add_field(name='Executes', value=f'{execution_human.title()}\n{execution_date} UTC', inline=True) response.add_field(name='Message', value=f'{choice["TextMessage"]}', inline=False) response.set_footer(text=f'ReminderID: {choice["ReminderID"]}') else: response = discord.Embed(color=0x0099FF) rem_list_out = '' for rem in reminder_list: exec_time = arrow.get(rem['ExecutionStamp']) human_time = exec_time.humanize(arrow.utcnow()) rem_text = f'**{rem["TextMessage"]}**\n - {human_time}' rem_list_out += f'\n{rem_text}' response.add_field(name=f'ℹ Reminder Data', value=f'You have {rem_count} pending reminders.', inline=False) response.add_field(name='Upcoming Reminders', value=f'{rem_list_out}', inline=False) response.set_footer(text=f'To see their details type {Prefix}reminders [0-{rem_count - 1}]') else: response = discord.Embed(color=0x696969, title='🔍 You have not made any reminders.') await message.channel.send(embed=response)
async def level(cmd, message, args): if message.mentions: target = message.mentions[0] else: target = message.author point_data = cmd.db.get_points(target) if not point_data: response = discord.Embed( color=0x696969, title=f'🔍 I couldn\'t find {target.name} in my point database.') await message.channel.send(None, embed=response) return total_pts = point_data['Total'] current_pts = point_data['Current'] servers = point_data['Servers'] curr_srv = 0 if str(message.guild.id) in servers: curr_srv = servers[str(message.guild.id)] response = discord.Embed(color=0x1ABC9C) response.set_author(name=f'{target.name}\'s Currency Data', icon_url=user_avatar(target)) response.add_field(name='Current Wallet', value=f'```py\n{current_pts} {Currency}\n```') response.add_field(name='This Server', value=f'```py\n{curr_srv} {Currency}\n```') response.add_field(name='Total Gained', value=f'```py\n{total_pts} {Currency}\n```') response.set_footer( text= f'{Currency} can be earned by being an active member of the server.') await message.channel.send(None, embed=response)
async def pmredirect(ev, message, args): cid = ev.bot.user.id author = message.author if not message.server: if author.id == cid or author.id in permitted_id: return else: if not message.content.startswith( Prefix) and author.id not in permitted_id: pm_response = discord.Embed( color=0x0099FF, title=f'ℹ Type `{Prefix}help` for info on how to use me!') await ev.bot.send_message(message.channel, None, embed=pm_response) ev.log.info( f'User {author.name} [{author.id}] sent a private message.') embed = discord.Embed(color=0x0099FF) if message.content and message.content != '': embed.add_field(name='Message', value='```\n' + message.content + '\n```', inline=False) embed.set_footer(text=f'UserID: {author.id}') embed.set_author(name=f'{author.name}#{author.discriminator}', icon_url=user_avatar(author)) if message.attachments: attachment_links = '' for attachment in message.attachments: attachment_links += '\n' + attachment['url'] embed.add_field(name='Attachments', value=attachment_links, inline=False) owner = discord.utils.find(lambda usr: usr.id == permitted_id[0], ev.bot.get_all_members()) await ev.bot.send_message(owner, None, embed=embed)
async def move_log_join(ev, member): try: log_channel_id = ev.db.get_settings(member.guild.id, 'LoggingChannel') except: log_channel_id = None if log_channel_id: log_channel = discord.utils.find(lambda x: x.id == log_channel_id, member.guild.channels) if log_channel: response = discord.Embed(color=0x66CC66, timestamp=arrow.utcnow().datetime) response.set_author(name=f'A Member Has Joined', icon_url=user_avatar(member)) response.add_field( name='📥 Joining Member', value=f'{member.mention}\n{member.name}#{member.discriminator}' ) new_acc, diff_msg = get_time_difference(member) if new_acc: response.add_field(name='❕ Account Is New', value=f'Made {diff_msg.title()}', inline=True) else: response.add_field(name='🕑 Account Created', value=f'{diff_msg.title()}', inline=True) response.set_footer(text=f'UserID: {member.id}') await log_channel.send(embed=response) else: ev.db.set_settings(member.guild.id, 'LoggingChannel', None)
async def inventory(cmd, message, args): if message.mentions: target = message.mentions[0] else: target = message.author inv = cmd.db.get_inv(target) if not inv: response = discord.Embed(color=0xc6e4b5, title='💸 Totally empty...') await message.channel.send(embed=response) size = len(inv) bordered_inv = inv[:20] headers = ['Item', 'Value'] to_format = [] for item in bordered_inv: to_format.append([item['name'], f'{item["value"]}']) output = boop(to_format,column_names=headers) inv_text = f'Showing the first {len(bordered_inv)} items.' inv_text += f'\nYou have a total of {size} items in your inventory.' response = discord.Embed(color=0xc16a4f) response.set_author(name=f'{target.name}#{target.discriminator}', icon_url=user_avatar(target)) response.add_field(name='📦 Inventory Stats', value=f'```py\n{inv_text}\n```') response.add_field(name='📋 Items Currently In It', value=f'```hs\n{output}\n```', inline=False) await message.channel.send(embed=response)
async def unban(cmd, message, args): if not check_ban(message.author, message.channel): response = discord.Embed( title='⛔ Unpermitted. Ban Permissions Needed.', color=0xDB0000) else: if args: user_search = ' '.join(args) target = None banlist = await message.guild.bans() for entry in banlist: if entry.user.name.lower() == user_search.lower(): target = entry.user break if target: await message.guild.unban( target, reason= f'Unbanned by {message.author.name}#{message.author.discriminator}.' ) response = discord.Embed( title=f'✅ {target.name} has been unbanned.', color=0x66CC66) # Logging Part try: log_channel_id = cmd.db.get_settings( message.guild.id, 'LoggingChannel') except: log_channel_id = None if log_channel_id: log_channel = discord.utils.find( lambda x: x.id == log_channel_id, message.guild.channels) if log_channel: log_response = discord.Embed( color=0x993300, timestamp=arrow.utcnow().datetime) log_response.set_author( name=f'A User Has Been Unbanned', icon_url=user_avatar(target)) log_response.add_field( name='🔨 Unbanned User', value= f'{target.mention}\n{target.name}#{target.discriminator}', inline=True) author = message.author log_response.add_field( name='🛡 Responsible', value= f'{author.mention}\n{author.name}#{author.discriminator}', inline=True) log_response.set_footer(text=f'UserID: {target.id}') await log_channel.send(embed=log_response) else: response = discord.Embed( title=f'🔍 {user_search} not found in the ban list.') else: response = discord.Embed(title='❗ No user targeted.', color=0xDB0000) await message.channel.send(embed=response)
async def kick(cmd, message, args): if not check_kick(message.author, message.channel): response = discord.Embed( title='⛔ Unpermitted. Kick Permissions Needed.', color=0xDB0000) else: if message.mentions: target = message.mentions[0] if target.id == message.author.id: response = discord.Embed(title='⛔ You can\'t kick yourself.', color=0xDB0000) else: if len(args) > 1: kick_reason = ' '.join(args[1:]) else: kick_reason = 'No reason given' await target.kick( reason= f'Kicked by {message.author.name}#{message.author.discriminator}.\n{kick_reason}' ) response = discord.Embed( title=f'👢 {target.name} has been kicked.', color=0x993300) # Logging Part try: log_channel_id = cmd.db.get_settings( message.guild.id, 'LoggingChannel') except: log_channel_id = None if log_channel_id: log_channel = discord.utils.find( lambda x: x.id == log_channel_id, message.guild.channels) if log_channel: log_response = discord.Embed( color=0x993300, timestamp=arrow.utcnow().datetime) log_response.set_author(name=f'A User Has Been Kicked', icon_url=user_avatar(target)) log_response.add_field( name='👢 Kicked User', value= f'{target.mention}\n{target.name}#{target.discriminator}', inline=True) author = message.author log_response.add_field( name='🛡 Responsible', value= f'{author.mention}\n{author.name}#{author.discriminator}', inline=True) log_response.add_field( name='📄 Reason', value=f"```\n{kick_reason}\n```", inline=False) log_response.set_footer(text=f'UserID: {target.id}') await log_channel.send(embed=log_response) else: response = discord.Embed(title='❗ No user targeted.', color=0xDB0000) await message.channel.send(embed=response)
async def fish(cmd, message, args): global all_fish if not all_fish: with open(cmd.resource('data/fish.yml')) as fish_file: all_fish = yaml.safe_load(fish_file) if cmd.cooldown.on_cooldown(cmd, message): timeout = cmd.cooldown.get_cooldown(cmd, message) response = discord.Embed( color=0x696969, title=f'🕙 Your new bait will be ready in {timeout} seconds.') await message.channel.send(embed=response) return cmd.cooldown.set_cooldown(cmd, message, 20) kud = cmd.db.get_points(message.author) if kud['Current'] < 20: response = discord.Embed(color=0xDB0000, title=f'You don\'t have enough {Currency}!') await message.channel.send(embed=response) return cmd.db.take_points(message.guild, message.author, 20) rarity = roll_rarity() item = random.choice(all_fish[rarity]) if 'connector' in item: connector = item['connector'] elif item['name'][0].lower() in ['a', 'e', 'i', 'o', 'u']: connector = 'an' else: connector = 'a' item_text = f'{connector} {item["name"]}' value = item['value'] if value == 0: notify_text = 'You threw it away.\nThis item is **worthless**.' else: item_id = make_item_id(message) item.update({'ItemID': item_id}) cmd.db.inv_add(message.author, item) notify_text = f'This item is valued at **{value} {Currency}**.' notify_text += f'\nIt has been added to your inventory.' notify_text += f'\nYou can sell it by using the {Prefix}sell command.' response = discord.Embed(color=visuals[rarity]['color']) response.add_field( name= f'{visuals[rarity]["icon"]} You caught {item_text} of {rarity} quality!', value=notify_text) response.set_footer(text=f'You paid 20 {Currency} for the bait.', icon_url=user_avatar(message.author)) await message.channel.send(embed=response)
def refactor_users_node(db, usrgen): db['UserList'].drop() for user in usrgen: user_ava = user_avatar(user) data = { 'UserID': user.id, 'UserName': user.name, 'Avatar': user_ava, 'Discriminator': user.discriminator } db['UserList'].insert_one(data)
async def notify_channel_of_special(message, all_channels, channel_id, item): if channel_id: target = discord.utils.find(lambda x: x.id == channel_id, all_channels) if target: connector = 'a' if item.rarity_name[0].lower() in ['a', 'e', 'i', 'o', 'u']: connector = 'an' response_title = f'{item.icon} {connector.title()} {item.rarity_name} {item.name} has been caught!' response = discord.Embed(color=item.color, title=response_title) response.set_author(name=f'{message.author.display_name}', icon_url=user_avatar(message.author)) response.set_footer(text=f'From {message.guild.name}.', icon_url=message.guild.icon_url) await target.send(embed=response)
async def remind(cmd, message, args): if not args: response = discord.Embed(color=0xDB0000, title='❗ No arguments inputted.') await message.channel.send(embed=response) return time_req = args[0] try: in_seconds = convert_to_seconds(time_req) if len(args) > 1: text_message = ' '.join(args[1:]) else: text_message = 'No reminder message set.' execution_stamp = arrow.utcnow().timestamp + in_seconds timestamp = arrow.get(execution_stamp).datetime if in_seconds < 60: time_diff = f'In {in_seconds} seconds' else: time_diff = arrow.get(execution_stamp).humanize(arrow.utcnow()) crypt = hashlib.new('md5') crypt.update(f'{message.id}+{execution_stamp}'.encode('utf-8')) final = crypt.hexdigest() reminder_data = { 'ReminderID': final, 'UserID': message.author.id, 'CreationStamp': arrow.utcnow().timestamp, 'ExecutionStamp': execution_stamp, 'ChannelID': message.channel.id, 'ServerID': message.guild.id, 'TextMessage': text_message } cmd.db.insert_one('Reminders', reminder_data) response = discord.Embed(color=0x66CC66, timestamp=timestamp) response.set_author(name='New Reminder Set', icon_url=user_avatar(message.author)) response.add_field(name='🕑 Until Reminder', value=time_diff.title(), inline=False) response.add_field(name='🗒 Reminder Message', value=text_message, inline=False) await message.channel.send(embed=response) except LookupError: response = discord.Embed(color=0xDB0000, title='❗ Please use the format HH:MM:SS.') await message.channel.send(embed=response) except ValueError: response = discord.Embed(color=0xDB0000, title='❗ Inputted value is invalid.') await message.channel.send(embed=response)
async def nowplaying(cmd, message, args): if message.server.id in cmd.music.currents: item = cmd.music.currents[message.server.id] req = item['requester'] video = item['video'] url = item['url'] embed = discord.Embed(color=0x0099FF) embed.set_thumbnail(url=video.thumb) embed.set_author(name=f'{req.name}#{req.discriminator}', icon_url=user_avatar(req), url=url) embed.add_field(name=':information_source: Currently Playing', value=f'{video.title}') embed.set_footer(text=f'Duration: {video.duration} | Click the author above to go to that video.') await cmd.bot.send_message(message.channel, None, embed=embed) else: embed = discord.Embed(color=0x0099FF, title=':information_source: No Currently Playing Item') await cmd.bot.send_message(message.channel, None, embed=embed)
async def inventory(cmd, message, args): if not items: get_all_items('fish', cmd.resource('data')) if message.mentions: target = message.mentions[0] else: target = message.author page_number = 1 if args: try: page_number = abs(int(args[0])) if page_number == 0: page_number = 1 except TypeError: page_number = 0 except ValueError: page_number = 0 start_range = (page_number - 1) * 10 end_range = page_number * 10 inv = cmd.db.get_inv(target) total_inv = len(inv) item_o_list = [] for item in inv: item_o = get_item_by_id(item['item_file_id']) item_o_list.append(item_o) item_o_list = sorted(item_o_list, key=lambda x: x.rarity, reverse=True) inv = item_o_list[start_range:end_range] if inv: headers = ['Type', 'Item', 'Value', 'Rarity'] to_format = [] total_value = 0 for item_o_item in inv: to_format.append( [item_o_item.item_type, item_o_item.name, f'{item_o_item.value}', f'{item_o_item.rarity_name.title()}']) for item_o_item in item_o_list: total_value += item_o_item.value output = boop(to_format, column_names=headers) response = discord.Embed(color=0xc16a4f) response.set_author(name=f'{target.name}#{target.discriminator}', icon_url=user_avatar(target)) inv_text = f'Showing {len(inv)}/{total_inv} items in your inventory.' inv_text += f'\nTotal value of your inventory is {total_value} {Currency}.' response.add_field(name='📦 Inventory Stats', value=f'```py\n{inv_text}\n```') response.add_field(name=f'📋 Items Currently On Page {page_number}', value=f'```hs\n{output}\n```', inline=False) else: response = discord.Embed(color=0xc6e4b5, title='💸 Totally empty...') await message.channel.send(embed=response)
async def forage(cmd, message, args): all_plants = get_all_items('plants', cmd.resource('data')) if not cmd.cooldown.on_cooldown(cmd, message): cmd.cooldown.set_cooldown(cmd, message, 60) kud = cmd.db.get_points(message.author) if kud['Current'] >= 20: cmd.db.take_points(message.guild, message.author, 20) rarity = roll_rarity() if args: if message.author.id in permitted_id: try: rarity = int(args[0]) except TypeError: pass all_items_in_rarity = get_items_in_rarity(all_plants, rarity) item = secrets.choice(all_items_in_rarity) value = item.value connector = 'a' if item.rarity_name[0].lower() in ['a', 'e', 'i', 'o', 'u']: connector = 'an' if value == 0: response_title = f'{item.icon} You found {connector} {item.name} and threw it away!' else: response_title = f'{item.icon} You found {connector} {item.rarity_name} {item.name}!' item_id = make_item_id() data_for_inv = { 'item_id': item_id, 'item_file_id': item.item_file_id, } cmd.db.inv_add(message.author, data_for_inv) response = discord.Embed(color=item.color, title=response_title) response.set_author(name=message.author.display_name, icon_url=user_avatar(message.author)) if item.rarity >= 5: await notify_channel_of_special(message, cmd.bot.get_all_channels(), ItemWinChannelID, item) else: response = discord.Embed( color=0xDB0000, title=f'◠You don\'t have enough {Currency}!') else: timeout = cmd.cooldown.get_cooldown(cmd, message) response = discord.Embed( color=0x696969, title=f'🕙 Your new bait will be ready in {timeout} seconds.') await message.channel.send(embed=response)
async def rategirl(cmd, message, args): if message.mentions: target = message.mentions[0] else: target = message.author resize = True if args: if args[-1].lower() == 'large': resize = False size_x = 1355 size_y = 1226 min_x = 200 min_y = 1044 max_x = 1155 max_y = 182 spc_x = max_x - min_x spc_y = min_y - max_y output_location = f'cache/hcz_{message.id}.png' with Image.open(cmd.resource('rate/crazy_hot_chart.png')) as chart: perc_x = str(target.id)[6] + str(target.id)[9] perc_y = str(target.id)[12] + str(target.id)[3] loc_x = int(spc_x * (float(f'0.{perc_x}'))) loc_y = int(spc_y * (1 - (float(f'0.{perc_y}')))) ava_x = loc_x + 250 ava_y = loc_y + 108 ind_x = loc_x + 175 ind_y = loc_y + 108 ava_size = (145, 145) user_ava = user_avatar(target) async with aiohttp.ClientSession() as session: async with session.get(user_ava) as data: image_data = await data.read() user_ava = BytesIO(image_data) with Image.open(user_ava) as user_ava: user_ava = user_ava.resize(ava_size, Image.ANTIALIAS) chart.paste(user_ava, (ava_x, ava_y)) with Image.open(cmd.resource('rate/user_indicator.png')) as indicator: chart.paste(indicator, (ind_x, ind_y), indicator) if resize: chart = chart.resize((size_x // 2, size_y // 2), Image.ANTIALIAS) chart.save(output_location) with open(output_location, 'rb') as resp_img: resp = discord.File(resp_img) await message.channel.send(file=resp) os.remove(output_location)
async def refactor_users_node(db, usrgen): usrs = list(usrgen) db['UserList'].drop() db.log.info('UserList Dropped And Starting Refactoring Process...') start_time = arrow.utcnow().timestamp usercount = 0 for user in usrs: usercount += 1 user_ava = user_avatar(user) data = { 'UserID': user.id, 'UserName': user.name, 'Avatar': user_ava, 'Discriminator': user.discriminator } db['UserList'].insert_one(data) await asyncio.sleep(0.001) elapsed_time = arrow.utcnow().timestamp - start_time db.log.info(f'{usercount} Users Updated in {elapsed_time} seconds.')
async def rip(cmd, message, args): if message.mentions: target = message.mentions[0] else: target = message.author avatar_url = user_avatar(target) + '?size=128' async with aiohttp.ClientSession() as session: async with session.get(avatar_url) as data: avatar = await data.read() avatar = BytesIO(avatar) base = Image.open(cmd.resource('img/base.png')) tomb = Image.open(cmd.resource('img/tombstone.png')) avatar_img = Image.open(avatar) avatar_img = avatar_img.resize((108, 108), Image.ANTIALIAS) base.paste(avatar_img, (60, 164)) base.paste(tomb, (0, 0), tomb) base.save(f'cache/rip_{message.id}.png') await message.channel.send(file=discord.File(f'cache/rip_{message.id}.png')) os.remove(f'cache/rip_{message.id}.png')
async def triggered(cmd, message, args): if message.mentions: target = message.mentions[0] else: target = message.author if not cmd.cooldown.on_cooldown(cmd, message): cmd.cooldown.set_cooldown(cmd, message, 180) avatar_url = user_avatar(target) + '?size=512' wait_trig_response = discord.Embed(color=0xff6600, title='💥 Triggering...') resp_msg = await message.channel.send(embed=wait_trig_response) async with aiohttp.ClientSession() as session: async with session.get(avatar_url) as data: avatar_data = await data.read() avatar = Image.open(BytesIO(avatar_data)) avatar = avatar.resize((300, 300), Image.ANTIALIAS) image_list = [] for x in range(0, 30): base = Image.new('RGBA', (256, 320), (0, 0, 0, 0)) with Image.open(cmd.resource('trig_bot.png')) as trig_sign: move_max = 22 move_x = random.randint(-move_max, move_max) move_y = random.randint(-move_max, move_max) base.paste(avatar, (-22 + move_x, -22 + move_y)) base.paste(trig_sign, (0, 256)) temp_loc = f'temp_gif_cache_{random.randint(99, 999999)}.png' base.save(temp_loc) image_list.append(imageio.imread(temp_loc)) os.remove(temp_loc) out_loc = f'cache/triggered_{message.id}.gif' imageio.mimsave(out_loc, image_list, fps=30) dfile = discord.File(out_loc) await message.channel.send(file=dfile) try: await resp_msg.delete() except: pass os.remove(out_loc) else: cdembed = discord.Embed( color=0x696969, title=f'🕙 {target.name} has been put on ice to cool off.') await message.channel.send(embed=cdembed)
async def textmute(cmd, message, args): if not check_man_msg(message.author, message.channel): response = discord.Embed(title='⛔ Unpermitted. Manage Messages Permission Needed.', color=0xDB0000) else: if not message.mentions: response = discord.Embed(title='❗ No user targeted.', color=0xDB0000) else: target = message.mentions[0] if target.id != message.author.id or check_admin(target, message.channel): try: mute_list = cmd.db.get_settings(message.guild.id, 'MutedUsers') except: mute_list = [] if target.id in mute_list: response = discord.Embed(title='❗ User already muted.', color=0xDB0000) else: mute_list.append(target.id) cmd.db.set_settings(message.guild.id, 'MutedUsers', mute_list) response = discord.Embed(color=0x66CC66, title=f'✅ {target.name}#{target.discriminator} has been text muted.') try: log_channel_id = cmd.db.get_settings(message.guild.id, 'LoggingChannel') except: log_channel_id = None if log_channel_id: log_channel = discord.utils.find(lambda x: x.id == log_channel_id, message.guild.channels) if log_channel: log_embed = discord.Embed(color=0x696969, timestamp=arrow.utcnow().datetime) log_embed.set_author(name='A Member Has Been Muted', icon_url=user_avatar(target)) log_embed.add_field(name='🔇 Muted User', value=f'{target.mention}\n{target.name}#{target.discriminator}', inline=True) author = message.author log_embed.add_field(name='🛡 Responsible', value=f'{author.mention}\n{author.name}#{author.discriminator}', inline=True) if len(args) > 1: log_embed.add_field(name='📄 Reason', value=f"```\n{' '.join(args[1:])}\n```", inline=False) log_embed.set_footer(text=f'UserID: {target.id}') await log_channel.send(embed=log_embed) else: response = discord.Embed(title='❗ You can\'t mute yourself.', color=0xDB0000) await message.channel.send(embed=response)
async def prune(cmd, message, args): channel = message.channel if check_man_msg(message.author, channel): limit = 100 target = cmd.bot.user if not args: limit = 100 target = cmd.bot.user if len(args) == 1 and message.mentions: limit = 100 target = message.mentions[0] if len(args) > 1 and message.mentions: target = message.mentions[0] limit = abs(int(args[0])) if len(args) == 1 and not message.mentions: target = None limit = abs(int(args[0])) try: await message.delete() except: pass def author_check(msg): return msg.author.id == target.id if target: deleted = await message.channel.purge(limit=limit, check=author_check) else: deleted = await message.channel.purge(limit=limit) embed = discord.Embed(color=0x66CC66, title=f'✅ Deleted {len(deleted)} Messages') try: log_channel_id = cmd.db.get_settings(message.guild.id, 'LoggingChannel') except: log_channel_id = None if log_channel_id: log_channel = discord.utils.find(lambda x: x.id == log_channel_id, message.guild.channels) if log_channel: response = discord.Embed(color=0x696969, timestamp=arrow.utcnow().datetime) response.set_author(name=f'#{channel.name} Has Been Pruned', icon_url=user_avatar(message.author)) if target: target_text = f'{target.mention}' else: target_text = 'No Filter' response.add_field( name='🗑 Prune Details', value= f'Amount: {len(deleted)} Messages\nTarget: {target_text}', inline=True) author = message.author response.add_field( name='🛡 Responsible', value= f'{author.mention}\n{author.name}#{author.discriminator}', inline=True) response.set_footer(text=f'ChannelID: {channel.id}') await log_channel.send(embed=response) else: embed = discord.Embed( title= '⚠ Unpermitted. Only Those With The Manage Message Permission Allowed.', color=0xDB0000) notify_msg = await message.channel.send(None, embed=embed) await asyncio.sleep(5) try: await notify_msg.delete() except: pass
async def warn_action(cmd, guild, channel, target, author, warning_text): if not warning_text or warning_text == '': warning_text = 'No Reason Given' try: warned_users = cmd.db.get_settings(str(guild.id), 'WarnedUsers') except KeyError: cmd.db.set_settings(str(guild.id), 'WarnedUsers', {}) warned_users = {} target_id = str(target.id) if target_id in warned_users: if warned_users[target_id]['Warns'] >= 2: out_content_local = discord.Embed(color=0xFF4400, title=f'⚠ {target.name} had 3 warnings.') await channel.send(None, embed=out_content_local) await target.kick(reason=f'Kicked by {author.name}#{author.discriminator}.\n Has 3 or more warnings') # \NOTE: The rest will not happen if the bot has failed to kick the user (user is admin, server owner, etc) try: warn_data = { 'UserID': str(warned_users[target_id]['UserID']), 'Warns': warned_users[target_id]['Warns'] + 1, 'Reasons': warned_users[target_id]['Reasons'] + [warning_text], 'Timestamp': warned_users[target_id]['Timestamp'] + [str(arrow.utcnow().timestamp)] } except: warn_data = { 'UserID': str(warned_users[target_id]['UserID']), 'Warns': warned_users[target_id]['Warns'] + 1, 'Reasons': warned_users[target_id]['Reasons'] + [warning_text], 'Timestamp': [str(warned_users[target_id]['Timestamp'])] + [str(arrow.utcnow().timestamp)] } else: warn_data = { 'UserID': str(target.id), 'Warns': 1, 'Reasons': [warning_text], 'Timestamp': [str(arrow.utcnow().timestamp)] } warned_users.update({ target_id: warn_data }) cmd.db.set_settings(str(guild.id), 'WarnedUsers', warned_users) out_content_to_user = discord.Embed(color=0xFF9900) out_content_to_user.add_field(name=f'⚠ Warning on {guild.name}', value=f'Reason:\n```\n{warning_text}\n```') try: await target.send(None, embed=out_content_to_user) except: pass # Logging Part try: mod_notifications_enabled = cmd.db.get_settings(guild.id, 'ModeratorNotifications') if not mod_notifications_enabled: raise Exception modchannel_id = cmd.db.get_settings(guild.id, 'ModeratorChannel') modchannel = discord.utils.find(lambda c: c.id == modchannel_id, guild.channels) except: cmd.log.info('[WARNS] No moderator notification sent because server named ' + guild.name + \ ' does not have a moderator channel set up') else: response = discord.Embed(color=0xFF9900, timestamp=arrow.utcnow().datetime) response.set_author(name=f'A User Has Been Warned', icon_url=user_avatar(target)) response.add_field(name='⚠ Warned User', value=f'{target.mention}\n{target.name}#{target.discriminator}', inline=True) response.add_field(name='🛡 Responsible', value=f'{author.mention}\n{author.name}#{author.discriminator}', inline=True) if warning_text: response.add_field(name='📄 Reason', value=f"```\n{warning_text}\n```", inline=False) response.set_footer(text=f'UserID: {target.id}') await modchannel.send(embed=response)
async def play(cmd, message, args): if args: task = cmd.bot.plugin_manager.commands['queue'].call(message, args) await task if message.guild.id not in cmd.music.initializing: bot_voice = message.guild.voice_client if not message.author.voice: embed = discord.Embed( title='⚠ I don\'t see you in a voice channel', color=0xFF9900) await message.channel.send(None, embed=embed) return srv_queue = cmd.music.get_queue(message.guild.id) if srv_queue.empty(): embed = discord.Embed(title='⚠ The queue is empty', color=0xFF9900) await message.channel.send(None, embed=embed) return cmd.music.add_init(message.guild.id) cmd.bot.loop.create_task(init_clock(cmd.music, message.guild.id)) if not bot_voice: try: try: can_connect = message.guild.me.permissions_in( message.author.voice.channel).connect can_talk = message.guild.me.permissions_in( message.author.voice.channel).speak if can_connect and can_talk: bot_voice = await message.author.voice.channel.connect( ) else: embed = discord.Embed( title= f'⚠ I am not allowed to join {message.author.voice.channel.name}.', color=0xFF9900) await message.channel.send(None, embed=embed) return except discord.ClientException: bot_voice = None for voice_instance in cmd.bot.voice_clients: if voice_instance.guild.id == message.guild.id: bot_voice = voice_instance embed = discord.Embed(title='✅ Joined ' + message.author.voice.channel.name, color=0x66cc66) except SyntaxError as e: cmd.log.error(f'ERROR: {e} | TRACE: {e.with_traceback}') embed = discord.Embed(color=0xDB0000) embed.add_field( name='❗ I was unable to connect.', value= 'The most common cause is your server being too far or a poor connection.' ) await message.channel.send(None, embed=embed) if bot_voice: if bot_voice.is_playing(): if not args: embed = discord.Embed( title= f'⚠ Already playing in {message.guild.get_member(cmd.bot.user.id).voice.channel.name}', color=0xFF9900) await message.channel.send(None, embed=embed) return while music_is_ongoing(cmd, message.guild.id, message.guild.me.voice): item = await cmd.music.get_from_queue(message.guild.id) if message.guild.id in cmd.music.repeaters: await cmd.music.add_to_queue(message.guild.id, item) cmd.music.currents.update({message.guild.id: item}) sound = item['sound'] try: await cmd.music.make_player(bot_voice, item) except: pass add_special_stats(cmd.db, 'songs_played') embed = discord.Embed(color=0x0099FF) if item['type'] == 0: embed.add_field(name='🎵 Now Playing', value=sound.title) embed.set_thumbnail(url=sound.thumb) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) embed.set_footer(text=f'Duration: {sound.duration}') elif item['type'] == 1: embed.add_field(name='🎵 Now Playing', value=sound['title']) embed.set_thumbnail(url=sound['artwork_url']) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) elif item['type'] == 2: embed.add_field(name='🎵 Now Playing', value=f"{sound['artist']} - {sound['title']}") embed.set_thumbnail(url=sound['thumbnail']) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) duration = f'Duration: {time.strftime("%H:%M:%S", time.gmtime(int(item["sound"]["duration"])))}' embed.set_footer(text=duration) else: return await message.channel.send(None, embed=embed) while bot_voice.is_playing(): await asyncio.sleep(2) try: await bot_voice.disconnect() except: pass try: del cmd.music.currents[message.guild.id] except: pass else: cmd.log.warning( 'Play Command Ignored Due To Server Being In The Music Initialization List' )
async def queue(cmd, message, args): if message.author.voice: if args: qry = ' '.join(args) if '?list=' in qry: list_id = qry.split('list=')[1].split('&')[0] plist = pafy.get_playlist2(list_id) item_count = yt_playlist_adder(message.guild.id, cmd, message.author, plist) embed_title = f'ℹ Added {item_count} items from {plist.title}.' embed = discord.Embed(color=0x0099FF, title=embed_title) await message.channel.send(None, embed=embed) await asyncio.sleep(3) else: if qry.startswith('https://'): if 'youtu' in qry: song_url = qry sound = pafy.new(song_url) sound_type = 0 elif 'soundcloud' in qry: song_url = qry sc_cli = soundcloud.Client( client_id=SoundCloudClientID) sound = sc_cli.get('/resolve', url=qry).fields() sound_type = 1 else: response = discord.Embed( color=0xDB0000, title='❗ Unsupported URL Provided') response.set_footer( text= 'We only support YouTube and SoundCloud for now.') return else: song_url = await search_youtube(qry) sound = pafy.new(song_url) sound_type = 0 data = { 'url': song_url, 'type': sound_type, 'requester': message.author, 'sound': sound, 'timestamp': arrow.now().timestamp } embed = discord.Embed(color=0x66CC66) cmd.bot.music.add_to_queue(message.guild.id, data) if sound_type == 0: embed.add_field(name='✅ Added To Queue', value=sound.title) embed.set_thumbnail(url=sound.thumb) embed.set_author( name= f'{message.author.name}#{message.author.discriminator}', icon_url=user_avatar(message.author)) embed.set_footer(text=f'Duration: {sound.duration}') elif sound_type == 1: embed.add_field(name='✅ Added To Queue', value=sound['title']) embed.set_thumbnail(url=sound['artwork_url']) embed.set_author( name= f'{message.author.name}#{message.author.discriminator}', icon_url=user_avatar(message.author)) else: return await message.channel.send(None, embed=embed) else: q = cmd.bot.music.get_queue(message.guild.id) if q.empty(): embed = discord.Embed(color=0x0099FF, title='ℹ The Queue Is Empty') await message.channel.send(None, embed=embed) else: q_list = list(q.queue)[:5] embed = discord.Embed( color=0x0099FF, title= f'ℹ The {len(q_list)} Upcoming Songs (Total: {len(list(q.queue))})' ) for item in q_list: if item['type'] == 0: information = f'Requested By: {item["requester"].name}\nDuration: {item["sound"].duration}' embed.add_field(name=item['sound'].title, value=f'```\n{information}\n```', inline=False) elif item['type'] == 1: information = f'Requested By: {item["requester"].name}\nDuration: {time.strftime("%H:%M:%S", time.gmtime(item["sound"]["duration"]//1000))}' embed.add_field(name=item['sound']['title'], value=f'```\n{information}\n```', inline=False) embed.set_footer( text=f'To see the currently playing song type {Prefix}np') await message.channel.send(None, embed=embed)
async def collectchain(cmd, message, args): global in_use global in_use_by if in_use: response = discord.Embed(color=0x696969, title='🛠 Currently in use. Try Again Later.') response.set_author(name=f'{in_use_by.name}', icon_url=user_avatar(in_use_by)) await message.channel.send(None, embed=response) else: if args: if message.mentions: target = message.mentions[0] else: target = discord.utils.find( lambda x: x.name.lower() == ' '.join(args).lower(), message.guild.members) if target: start_time = arrow.utcnow().timestamp if message.channel_mentions: target_chn = message.channel_mentions[0] else: target_chn = message.guild.default_channel collected = 0 collection = [] in_use = True in_use_by = message.author ch_response = discord.Embed( color=0x66CC66, title= '📖 Collecting... You will be sent a DM when I\'m done.') await message.channel.send(None, embed=ch_response) async for log in target_chn.history(limit=50000): if log.author.id == target.id: if log.content: if log.content != '': if len(log.content) > 3: if not check_for_bot_prefixes(log.content): if 'http' not in log.content and '```' not in log.content: if '"' not in log.content: content = log.content if log.mentions: for mention in log.mentions: content = content.replace( mention.mention, mention.name) if log.channel_mentions: for mention in log.channel_mentions: content = content.replace( mention.mention, mention.name) unallowed_chars = [ '`', '\n', '\\', '\\n' ] for char in unallowed_chars: content = content.replace( char, '') if len(content) > 12: if not content.endswith( ('.' or '?' or '!')): content += '.' collection.append(content) collected += 1 if collected >= 3000: break cmd.db.delete_one('MarkovChains', {'UserID': target.id}) data = {'UserID': target.id, 'Chain': collection} cmd.db.insert_one('MarkovChains', data) in_use = False in_use_by = None dm_response = discord.Embed( color=0x66CC66, title=f'📖 {target.name}\'s chain is done!') dm_response.add_field(name='Amount Collected', value=f'```\n{collected}\n```') dm_response.add_field( name='Time Elapsed', value=f'```\n{arrow.utcnow().timestamp - start_time}s\n```' ) await message.author.send(None, embed=dm_response) await message.channel.send(None, embed=dm_response) if message.author.id != target.id: tgt_msg = discord.Embed( color=0x66CC66, title= f'📖 {message.author.name} has made a markov chain for you.' ) await target.send(None, embed=tgt_msg)
async def play(cmd, message, args): if args: task = cmd.bot.plugin_manager.commands['queue'].call(message, args) cmd.bot.loop.create_task(task) if message.guild.id in cmd.music.voices: bot_voice = cmd.music.voices[message.guild.id] if bot_voice.is_playing(): return await asyncio.sleep(3) if message.guild.id not in cmd.music.initializing: if not message.author.voice: embed = discord.Embed( title='⚠ I don\'t see you in a voice channel', color=0xFF9900) await message.channel.send(None, embed=embed) return srv_queue = cmd.music.get_queue(message.guild.id) if len(srv_queue.queue) == 0: embed = discord.Embed(title='⚠ The queue is empty', color=0xFF9900) await message.channel.send(None, embed=embed) return cmd.music.add_init(message.guild.id) cmd.bot.loop.create_task(init_clock(cmd.music, message.guild.id)) if message.guild.id in cmd.music.voices: bot_voice = cmd.music.voices[message.guild.id] else: bot_voice = None if not bot_voice: try: bot_voice = await message.author.voice.channel.connect() cmd.music.voices.update({message.guild.id: bot_voice}) embed = discord.Embed(title='✅ Joined ' + message.author.voice.channel.name, color=0x66cc66) except SyntaxError as e: cmd.log.error(f'ERROR: {e} | TRACE: {e.with_traceback}') embed = discord.Embed(color=0xDB0000) embed.add_field( name='❗ I was unable to connect.', value= 'The most common cause is your server being too far or a poor connection.' ) await message.channel.send(None, embed=embed) if bot_voice: if bot_voice.is_playing(): embed = discord.Embed( title='⚠ Already playing in ' + cmd.bot.voice_client_in(message.guild).channel.name, color=0xFF9900) await message.channel.send(None, embed=embed) return while cmd.music.get_queue(message.guild.id) and len( cmd.music.get_queue(message.guild.id).queue) != 0: item = cmd.music.get_from_queue(message.guild.id) if message.guild.id in cmd.music.repeaters: cmd.music.add_to_queue(message.guild.id, item) cmd.music.currents.update({message.guild.id: item}) sound = item['sound'] cmd.bot.loop.create_task( cmd.music.make_player(message.guild.id, bot_voice, item)) await asyncio.sleep(2) def_vol = cmd.music.get_volume(cmd.db, message.guild.id) def_vol = def_vol / 100 bot_voice.source.volume = def_vol cmd.db.add_stats('MusicCount') embed = discord.Embed(color=0x0099FF) if item['type'] == 0: embed.add_field(name='🎵 Now Playing', value=sound.title) embed.set_thumbnail(url=sound.thumb) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) embed.set_footer(text=f'Duration: {sound.duration}') elif item['type'] == 1: embed.add_field(name='🎵 Now Playing', value=sound['title']) embed.set_thumbnail(url=sound['artwork_url']) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester']), url=item['url']) else: return await message.channel.send(None, embed=embed) while bot_voice.is_playing(): await asyncio.sleep(2) try: await bot_voice.disconnect() del cmd.music.voices[message.guild.id] except: pass del cmd.music.currents[message.guild.id] else: cmd.log.warning( 'Play Command Ignored Due To Server Being In The Music Initialization List' )
async def play(cmd, message, args): if args: await cmd.bot.plugin_manager.commands['queue'].call(message, args) player = cmd.music.get_player(message.server.id) if player: if player.is_playing(): return if not message.server.id in cmd.music.initializing: cmd.music.add_init(message.server.id) cmd.bot.loop.create_task(init_clock(cmd.music, message.server.id)) if not message.author.voice_channel: embed = discord.Embed( title=':warning: I don\'t see you in a voice channel', color=0xFF9900) await cmd.bot.send_message(message.channel, None, embed=embed) return srv_queue = cmd.music.get_queue(message.server.id) voice_connected = cmd.bot.is_voice_connected(message.server) if not voice_connected: await cmd.bot.join_voice_channel(message.author.voice_channel) embed = discord.Embed(title=':white_check_mark: Joined ' + message.author.voice_channel.name, color=0x66cc66) await cmd.bot.send_message(message.channel, None, embed=embed) if len(srv_queue.queue) == 0: embed = discord.Embed(title=':warning: The queue is empty', color=0xFF9900) await cmd.bot.send_message(message.channel, None, embed=embed) return player = cmd.music.get_player(message.server.id) if player: if player.is_playing(): embed = discord.Embed( title=':warning: Already playing in ' + cmd.bot.voice_client_in(message.server).channel.name, color=0xFF9900) await cmd.bot.send_message(message.channel, None, embed=embed) return voice_instance = cmd.bot.voice_client_in(message.server) while cmd.music.get_queue(message.server.id) and len( cmd.music.get_queue(message.server.id).queue) != 0: item = cmd.music.get_from_queue(message.server.id) cmd.music.currents.update({message.server.id: item}) video = item['video'] item_url = item['url'] await cmd.music.make_yt_player(message.server.id, voice_instance, item_url) player = cmd.music.get_player(message.server.id) if not player: print('No player.') return def_vol = cmd.music.get_volume(cmd.db, message.server.id) player.volume = def_vol / 100 player.start() cmd.db.add_stats('MusicCount') embed = discord.Embed(color=0x0099FF) embed.add_field(name='🎵 Now Playing', value=video.title) embed.set_thumbnail(url=video.thumb) embed.set_author( name= f'{item["requester"].name}#{item["requester"].discriminator}', icon_url=user_avatar(item['requester'])) embed.set_footer(text=f'Duration: {video.duration}') await cmd.bot.send_message(message.channel, None, embed=embed) while not player.is_done(): await asyncio.sleep(2) cmd.music.kill_player(message.server.id) try: await voice_instance.disconnect() except: pass del cmd.music.currents[message.server.id] else: cmd.log.warning( 'Play Command Ignored Due To Server Being In The Music Initialization List' )