async def decrypt(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ text = False cipher = get_encryptor(cmd.bot.cfg) if cipher: if pld.args: if pld.args[-1] == ':t': text = True crypt_text = ''.join(pld.args[:-1]).encode('utf-8') else: crypt_text = ''.join(pld.args).encode('utf-8') try: ciphered = cipher.decrypt(crypt_text).decode('utf-8') except InvalidToken: ciphered = None except InvalidSignature: ciphered = None if ciphered: if text: response = escape_mentions(ciphered) else: response = discord.Embed(color=0xe75a70) response.add_field(name='💟 Token Decrypted', value=ciphered) else: response = GenericResponse( 'The token or key are incorrect.').error() else: response = GenericResponse('Nothing to decrypt.').error() else: response = GenericResponse('You don\'t possess a key.').error() if text: await pld.msg.channel.send(response) else: await pld.msg.channel.send(embed=response)
async def giverole(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.guild_permissions.manage_roles: if pld.args: if len(pld.args) >= 2: if pld.msg.mentions: target = pld.msg.mentions[0] lookup = ' '.join(pld.args[1:]).lower() target_role = discord.utils.find( lambda x: x.name.lower() == lookup, pld.msg.guild.roles) if target_role: role_below = target_role.position < pld.msg.guild.me.top_role.position if role_below: user_has_role = discord.utils.find( lambda x: x.name.lower() == lookup, target.roles) if not user_has_role: author = f'{pld.msg.author.name}#{pld.msg.author.discriminator}' await target.add_roles( target_role, reason=f'Role given by {author}.') response = GenericResponse( f'{target_role.name} has been given to {target.name}.' ).ok() else: response = GenericResponse( 'That user already has this role.').error( ) else: response = GenericResponse( 'This role is above my highest role.').error() else: response = GenericResponse( f'{lookup} not found.').not_found() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse('Not enough arguments.').error() else: response = GenericResponse('Nothing inputted.').error() else: response = GenericResponse( 'Access Denied. Manage Roles needed.').denied() await pld.msg.channel.send(embed=response)
async def generateresource(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.mentions: if len(pld.args) >= 3: target = pld.msg.mentions[0] if not target.bot: try: amount = abs(int(pld.args[-1])) currency = cmd.bot.cfg.pref.currency.lower() res_nam = 'currency' if pld.args[0].lower() == currency else pld.args[0].lower() valid_res = f'{res_nam.title()}Resource' in await cmd.db[cmd.db.db_nam].list_collection_names() if valid_res: await cmd.db.add_resource(target.id, res_nam, amount, cmd.name, pld.msg, False) response = GenericResponse(f'Ok, I\'ve given {amount} {res_nam} to {target.display_name}.').ok() else: response = GenericResponse(f'No resource named {res_nam}.').error() except ValueError: response = GenericResponse('Invalid amount.').error() else: response = GenericResponse('You can\'t give resources to bots.').error() else: response = GenericResponse('Resource name, amount and target needed.').error() else: response = GenericResponse('No user targeted.').error() await pld.msg.channel.send(embed=response)
async def approvesuggestion(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if len(pld.args) >= 3: token, title, description = parse_approval(pld.args) suggestion = await cmd.db[cmd.db.db_nam].Suggestions.find_one( {'suggestion.id': token}) if suggestion: await react_to_suggestion(cmd.bot, suggestion, '✅', False) make_issue = False if title.lower().startswith('noissue') else True title = title if make_issue else title.partition(' ')[2] gl_desc = make_gl_suggestion(token, description, suggestion) gl_issue_url = None if cmd.cfg.token and cmd.cfg.project and make_issue: gl_issue_url = await submit_gl_issue(cmd.cfg.token, cmd.cfg.project, title, gl_desc) athr = await cmd.bot.get_user(suggestion.get('user', {}).get('id')) if athr: to_user = GenericResponse( f'Suggestion {token} approved by {pld.msg.author.display_name}.' ).ok() if gl_issue_url: to_user_desc = 'Your suggestion was approved, you can view its status and details [here]' to_user_desc += f'({gl_issue_url}). If you need info, the support server is in the help command.' else: to_user_desc = f'```md\n{gl_desc}\n```' to_user.description = to_user_desc try: await athr.send(embed=to_user) response = GenericResponse( f'Suggestion {token} approved.').ok() except (discord.Forbidden, discord.NotFound): response = GenericResponse( f'Suggestion {token} approved, but delivery to author failed.' ).ok() else: response = GenericResponse( f'Suggestion {token} approved, but the author was not found.' ).ok() else: response = GenericResponse( 'No suggestion entry with that ID was found.').error() else: response = GenericResponse('Not enough arguments.').error() await pld.msg.channel.send(embed=response)
async def pythonpackage(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: lookup = '_'.join(pld.args) package_url = f'https://pypi.org/pypi/{lookup}/json' try: package_data = await aioget(package_url, True) except json.decoder.JSONDecodeError: package_data = None if package_data: cdat = package_data.get('info') vers = package_data.get('releases') versions = filter(lambda v: v[1], vers.items()) versions = sorted(versions, key=lambda x: arrow.get(x[1][0].get('upload_time')).int_timestamp) if versions: created_at = arrow.get(versions[0][1][0].get('upload_time')) updated_at = arrow.get(versions[-1][1][0].get('upload_time')) package_page = cdat.get('package_url') package_title = f'{cdat.get("name")} {versions[-1][0]}' response = discord.Embed(color=0x3476a9, timestamp=updated_at.datetime) response.description = f'Author: {cdat.get("author") or "Unknown"}' response.description += f'\nCreated: {created_at.format("DD. MMM. YYYY")}' response.description += f'\n**{cdat.get("summary") or "No summary provided."}**' response.set_author(name=package_title, icon_url=pypi_io_icon, url=package_page) if cdat.get('keywords'): response.set_footer(text=f'Keywords: {", ".join(cdat.get("keywords").split())}') else: response.set_footer(text='Last updated') else: response = GenericResponse('Insufficient data on that package.').error() else: response = GenericResponse('Package not found.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def reminderinfo(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: rem_id = pld.args[0].lower() lookup_data = {'user_id': pld.msg.author.id, 'reminder_id': rem_id} reminder = await cmd.db[cmd.db.db_nam].Reminders.find_one(lookup_data) if reminder: execution_stamp = reminder['execution_stamp'] text_message = reminder['text_message'] timestamp = arrow.get(execution_stamp).datetime human_time = arrow.get(execution_stamp).humanize(arrow.utcnow()) auth_title = f'{pld.msg.author.display_name}\'s Reminder: {rem_id}' channel = await cmd.bot.get_channel(reminder.get('channel_id')) if channel: chan_name = f'**#{channel.name}**' srv_name = f'**{channel.guild.name}**' else: chan_name = '*{No Channel}*' srv_name = '*{No Server}*' location_text = f'Executes in {chan_name} on {srv_name} {human_time}.' response = discord.Embed(color=0x66CC66, timestamp=timestamp) response.add_field(name='🏛 Location', value=location_text, inline=False) response.add_field(name='🗒 Reminder Text', value=text_message, inline=False) response.set_author(name=auth_title, icon_url=user_avatar(pld.msg.author)) else: response = GenericResponse( f'Reminder `{rem_id}` not found.').not_found() else: response = GenericResponse('Missing reminder ID.').error() await pld.msg.channel.send(embed=response)
async def dictionary(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: query = '_'.join(pld.args).lower() lexico_url = f'https://www.lexico.com/en/definition/{query}' async with aiohttp.ClientSession() as session: async with session.get(lexico_url) as data_response: data = await data_response.text() data = scrape_lexico(data) if data: response = discord.Embed(color=0x50b46c) response.set_author(name=f'Lexico Dictionary: {data.get("word")}', icon_url=lexico_icon, url=lexico_url) for gramb in data.get('grambs'): gramb_lines = [] for trg in gramb.get('trgs'): gramb_lines.append( f'**{trg.get("index")}.** {trg.get("context")}') for sub in trg.get("subsenses"): gramb_lines.append( f'-> **{trg.get("index")}.{sub.get("index")}.** {sub.get("context")}' ) gramb_text = '\n'.join(gramb_lines[:10]) if gramb_text: response.add_field(name=gramb.get("type"), value=gramb_text, inline=False) if data.get('audio'): response.description = f'{data.get("word")} Pronunciation Audio: [Here]({data.get("audio")})' else: response = GenericResponse('No results.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def marketlist(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ ic = await get_item_core(cmd.db) reci_core = await get_recipe_core(cmd.db) await check_expiry(cmd.db) lookup = get_filter(pld.args) entries = [] title = None if lookup: item = ic.get_item_by_name(lookup) if item: title = f'Cheapest {item.rarity_name} {item.name} listings.' sort = ('price', -1) entries = await MarketEntry.find_all_items(cmd.db, item.file_id, sort=sort) else: title = 'Most recent listings.' sort = ('stamp', -1) entries = await MarketEntry.find_all(cmd.db, sort=sort) if entries: total_count = len(entries) entries, page = PaginatorCore.paginate(entries, get_page_number(pld.args)) start_range, end_range = (page - 1) * 10, page * 10 headers = ['Type', 'Name', 'Price', 'Rarity'] to_format = [] for entry in entries: item = ic.get_item_by_file_id(entry.item) in_rec = '*' if is_ingredient(reci_core.recipes, item) else '' to_format.append([ item.type, f'{item.name}{in_rec}', f'{entry.price}', f'{item.rarity_name.title()}' ]) output = boop(to_format, column_names=headers) response = discord.Embed(color=0x4289c1) inv_text = f'Showing items {start_range}-{end_range}.' inv_text += f'\nThere are {total_count} items on the open market.' response.add_field(name=f'💶 {title}', value=f'```py\n{inv_text}\n```') response.add_field(name=f'📋 Items Currently On Page {page}', value=f'```hs\n{output}\n```', inline=False) else: response = GenericResponse( 'I couldn\'t find anything with that name.').error() await pld.msg.channel.send(embed=response)
async def geterror(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ trace_text = None if pld.args: token = pld.args[0] error_file = await cmd.db[cmd.bot.cfg.db.database ].Errors.find_one({'token': token}) if error_file: response, trace_text = SigmaError.make_error_embed(error_file) else: response = GenericResponse( 'No error with that token was found.').error() else: response = GenericResponse('Missing error token.').error() await pld.msg.channel.send(embed=response) if trace_text: await pld.msg.channel.send(trace_text)
async def imgur(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if cmd.cfg.client_id: if pld.args or pld.msg.attachments: image_url = pld.msg.attachments[ 0].url if pld.msg.attachments else pld.args[0] link = await upload_image(image_url, cmd.cfg.client_id) if link: response = discord.Embed(color=0x85BF25) response.set_author(name=link, icon_url=imgur_icon, url=link) else: response = GenericResponse('Bad image.').error() else: response = GenericResponse('Nothing inputted.').error() else: response = GenericResponse('The API Key is missing.').error() await pld.msg.channel.send(embed=response)
async def imdb(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: search = '%20'.join(pld.args) api_url = f'http://sg.media-imdb.com/suggests/{search[0].lower()}/{search}.json' async with aiohttp.ClientSession() as session: async with session.get(api_url) as data: search_data = await data.text() search_data = '('.join(search_data.split("(")[1:])[:-1] data = json.loads(search_data) data = data.get('d', [None])[0] if data: imdb_icon = 'https://ia.media-imdb.com/images/G/01/imdb/images/mobile/' imdb_icon += 'apple-touch-icon-web-152x152-1475823641._CB522736557_.png' title = data.get('l', 'Unknown') staring = data.get('s', 'Unknown') movie_id = data.get('id') year = data.get('y', 'Unknown') image = data.get('i', [None])[0] imdb_movie_url = f'http://www.imdb.com/title/{movie_id}/' movie_desc = f'IMDB Page: [Here]({imdb_movie_url})' movie_desc += f'\nRelease Year: {year}' movie_desc += f'\nStaring: {staring}' response = discord.Embed(color=0xebc12d) response.add_field(name=title, value=movie_desc) response.set_footer(text='From the Internet Movie DataBase.', icon_url=imdb_icon) if image: response.set_thumbnail(url=image) else: response = GenericResponse('No results.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def echo(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: content = f'👄 {" ".join(pld.args)[:1995]}' await pld.msg.channel.send(escape_mentions(content)) else: no_args = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=no_args)
async def deleterolegroup(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.guild_permissions.manage_guild: if pld.args: group_id = pld.args[0].lower() role_groups = pld.settings.get('role_groups') or {} if group_id in role_groups: role_groups.pop(group_id) await cmd.db.set_guild_settings(pld.msg.guild.id, 'role_groups', role_groups) response = discord.Embed(color=0xFFCC4D, title=f'🔥 Role group {group_id} has been deleted.') else: response = GenericResponse(f'Group {group_id} not found.').not_found() else: response = GenericResponse('Nothing inputted.').error() else: response = GenericResponse('Access Denied. Manage Server needed.').denied() await pld.msg.channel.send(embed=response)
async def togglestatus(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ rotation = cmd.bot.cfg.pref.status_rotation rotation, state = (False, '**disabled**') if rotation else (True, '**enabled**') cmd.bot.cfg.pref.status_rotation = rotation response = GenericResponse(f'Status rotation {state}.').ok() await pld.msg.channel.send(embed=response)
async def wikipedia(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: api_url = f'{api_base}&action=opensearch&search={" ".join(pld.args)}&redirects=resolve' async with aiohttp.ClientSession() as session: async with session.get(api_url) as qs_session: resp_data = await qs_session.read() search_data = json.loads(resp_data) if search_data[1]: exact_result = get_exact_results(search_data) if exact_result: lookup, wiki_url = exact_result summary_url = f'{api_base}&action=query&prop=extracts&exintro&explaintext&titles={lookup}' async with aiohttp.ClientSession() as session: async with session.get(summary_url) as qs_session: summ_res_data = await qs_session.read() summ_data = json.loads(summ_res_data) pages = summ_data.get('query', {}).get('pages', {}) page_id = list(pages.keys())[0] summ = pages.get(page_id) summ_title = summ.get('title') summ_content = summ.get('extract') if len(summ_content) > 1900: summ_content = shorten_sentences(summ_content) response = discord.Embed(color=0xF9F9F9) response.set_author(name=summ_title, icon_url=wiki_icon, url=wiki_url) response.description = summ_content else: response = GenericResponse('Search too broad, please be more specific.').error() else: response = GenericResponse('No results.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def removeresponder(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).manage_guild: if pld.args: trigger = ' '.join(pld.args).lower() auto_responses = pld.settings.get('responder_triggers') or {} if trigger.lower() in auto_responses: del auto_responses[trigger] await cmd.db.set_guild_settings(pld.msg.guild.id, 'responder_triggers', auto_responses) response = GenericResponse(f'{trigger} has been removed.').ok() else: response = GenericResponse('Trigger not found.').not_found() else: response = GenericResponse('Nothing inputted.').error() else: response = GenericResponse('Access Denied. Manage Server needed.').denied() await pld.msg.channel.send(embed=response)
async def leetspeak(_cmd, pld): """ :param _cmd: The command object referenced in the command. :type _cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: levels = ['basic', 'advanced', 'ultimate'] if pld.args[-1].startswith('level:'): level = pld.args[-1].split(':')[1].lower() text = ' '.join(pld.args[:-1]) if level not in levels: level = None else: text = ' '.join(pld.args) level = 'basic' if level: leet_url = 'http://www.robertecker.com/hp/research/leet-converter.php?lang=en' data = { 'textbox_input': text, 'language': 'en', 'encode': 'encode', 'modus': level } async with aiohttp.ClientSession() as session: api_data = await session.post(leet_url, data=data) page = await api_data.text() page = html.fromstring(page) table = page.cssselect('.mytable') text = table[0][0][1][2].text_content() response = discord.Embed(color=0x3B88C3) response.add_field(name=f'🔣 {level.title()} L33t Converter', value=text) else: response = GenericResponse('Invalid l33t level.').error() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def awardleaderboards(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: collections = await cmd.db[cmd.db.db_nam].list_collection_names() coll_title = pld.args[0].title() coll_title = 'Currency' if coll_title == cmd.bot.cfg.pref.currency.title() else coll_title if f'{coll_title}Resource' in collections: init_resp = discord.Embed(color=0xf9f9f9, title='💴 Awarding leaderboards....') init_msg = await pld.msg.channel.send(embed=init_resp) await reset_resource(cmd.db, cmd.log, coll_title) await init_msg.delete() response = GenericResponse('All leaderboards awarded.').ok() else: response = GenericResponse('Invalid collection.').error() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def viewincident(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).manage_messages: icore = get_incident_core(cmd.db) if len(pld.args) == 2: identifier = pld.args[0].lower() lookup = pld.args[1] if identifier in identifiers: if (identifier == 'order' and lookup.isdigit()) or identifier == 'id': if identifier == 'id': incident = await icore.get_by_token( pld.msg.guild.id, lookup) else: incident = await icore.get_by_order( pld.msg.guild.id, int(lookup)) if incident: icon, color = icons.get(incident.variant).values() response = incident.to_embed(icon, color) else: response = GenericResponse( f'No incident with that {identifier} found.' ).error() else: response = GenericResponse( 'Order must be a number.').error() else: response = GenericResponse('Invalid identifier.').error() else: response = GenericResponse('Invalid number of arguments.').error() else: response = GenericResponse( 'Access Denied. Manage Messages needed.').denied() await pld.msg.channel.send(embed=response)
async def cancelcollector(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ collector_coll = cmd.db[cmd.db.db_nam].CollectorQueue current = current_user_collecting if pld.msg.author.id != current: entry = await collector_coll.find_one({'user_id': pld.msg.author.id}) if entry: await collector_coll.delete_one(entry) response = GenericResponse( 'Ok, I removed you from the queue.').ok() else: response = GenericResponse( 'You are not currently in the queue.').error() else: response = GenericResponse( 'Can\'t cancel a already ongoing collection.').error() await pld.msg.channel.send(embed=response)
async def newdeck(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ new_deck = make_new_deck() cache_key = f'{cmd.name}_deck_{pld.msg.author.id}' await cmd.db.cache.set_cache(cache_key, new_deck) response = GenericResponse( f'Your deck has been rebuilt, {pld.msg.author.display_name}.').ok() await pld.msg.channel.send(embed=response)
async def getinteraction(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: react_id = pld.args[0].lower() react_item = await cmd.db[cmd.db.db_nam].Interactions.find_one( {'interaction_id': react_id}) if react_item: response = discord.Embed(color=0x5dadec, title=f'Click For Source', url=react_item.get("url")) response.set_image(url=react_item.get('url')) response.set_footer(text=f'Reaction ID: {react_id}') else: response = GenericResponse('Reaction not found.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def removeinteraction(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: lookup = pld.args[0].lower() interaction_item = await cmd.db[cmd.db.db_nam].Interactions.find_one( {'interaction_id': lookup}) if interaction_item: await cmd.db[cmd.db.db_nam ].Interactions.delete_one(interaction_item) response = discord.Embed( color=0xFFCC4D, title=f'🔥 Reaction `{lookup}` has been removed.') else: response = GenericResponse('Reaction not found.').not_found() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def activatewarning(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author == pld.msg.guild.owner: if pld.msg.mentions: if len(pld.args) == 2: target = pld.msg.mentions[0] warn_id = pld.args[1].lower() lookup = { 'guild': pld.msg.guild.id, 'target.id': target.id, 'warning.id': warn_id, 'warning.active': False } warn_data = await cmd.db[cmd.db.db_nam ].Warnings.find_one(lookup) if warn_data: warn_iden = warn_data.get('warning').get('id') change_data = {'$set': {'warning.active': True}} await cmd.db[cmd.db.db_nam ].Warnings.update_one(lookup, change_data) response = GenericResponse( f'Warning {warn_iden} reactivated.').ok() else: response = GenericResponse( 'Inactive warning not found.').not_found() else: response = GenericResponse( 'Both user tag and warning ID are needed.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse( 'Access Denied. Server Owner needed.').denied() await pld.msg.channel.send(embed=response)
async def listsettings(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if len(pld.args) > 1: mode = None valid_mode = True mode_name = pld.args[1].lower() if mode_name == 'private': mode = 'private' elif mode_name == 'locked': mode = 'locked' elif mode_name == 'public': mode = None else: valid_mode = False if valid_mode: lookup_data = {'server_id': pld.msg.guild.id, 'list_id': pld.args[0].lower()} list_coll = cmd.db[cmd.db.db_nam].CustomLists list_file = await list_coll.find_one(lookup_data) if list_file: list_id = list_file.get('list_id') if list_file.get('user_id') == pld.msg.author.id: list_file.update({'mode': mode}) await list_coll.update_one(lookup_data, {'$set': list_file}) response = GenericResponse(f'List `{list_id}` marked as {mode or "public"}.').ok() else: response = GenericResponse('You didn\'t make this list.').denied() else: response = GenericResponse('Invalid list ID.').error() else: response = GenericResponse('Invalid mode.').error() else: response = GenericResponse('Not enough arguments.').error() await pld.msg.channel.send(embed=response)
async def shadowpollvoters(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: poll_id = pld.args[0].lower() poll_file = await cmd.db[cmd.db.db_nam ].ShadowPolls.find_one({'id': poll_id}) if poll_file: author = poll_file['origin']['author'] if author == pld.msg.author.id: votes = poll_file['votes'] if votes: response = discord.Embed( color=0xF9F9F9, title=f'📨 Poll {poll_id} Voters') voter_lines = [] for voter_id in poll_file['votes'].keys(): voter_id = int(voter_id) voter = await cmd.bot.get_user(voter_id) if voter: voter_line = f'{voter.name}#{voter.discriminator}' else: voter_line = f'{voter_id}' voter_lines.append(voter_line) response.description = '\n'.join(voter_lines) else: response = GenericResponse('Nobody voted yet.').error() else: response = GenericResponse( 'You didn\'t make this poll.').denied() else: response = GenericResponse('Poll not found.').not_found() else: response = GenericResponse('Missing poll ID.').error() await pld.msg.channel.send(embed=response)
async def hardunmute(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).manage_channels: target = get_broad_target(pld) if target: hierarchy_me = hierarchy_permit(pld.msg.guild.me, target) if hierarchy_me: hierarchy_auth = hierarchy_permit(pld.msg.author, target) if hierarchy_auth: reason = ' '.join(pld.args[1:]) if pld.args[1:] else None await make_incident(cmd.db, pld.msg.guild, pld.msg.author, target, reason) ongoing = discord.Embed(color=0x696969, title='⛓ Editing permissions...') ongoing_msg = await pld.msg.channel.send(embed=ongoing) for channel in pld.msg.guild.channels: if isinstance(channel, discord.TextChannel) or isinstance(channel, discord.CategoryChannel): try: # noinspection PyTypeChecker await channel.set_permissions(target, overwrite=None, reason=reason) except discord.Forbidden: pass log_embed = generate_log_embed(pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_mutes') response = GenericResponse(f'{target.display_name} has been hard-unmuted.').ok() await ongoing_msg.delete() else: response = GenericResponse('That user is equal or above you.').error() else: response = GenericResponse('I can\'t mute a user equal or above me.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse('Access Denied. Manage Channels needed.').denied() await pld.msg.channel.send(embed=response)
async def givecurrency(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: if len(pld.args) >= 2: if pld.msg.mentions: target = pld.msg.mentions[0] if not target.bot: try: amount = abs(int(pld.args[-1])) except ValueError: amount = None if amount: target_sabotaged = await cmd.db.is_sabotaged(target.id) author_sabotaged = await cmd.db.is_sabotaged( pld.msg.author.id) if not target_sabotaged and not author_sabotaged: current_kud = await cmd.db.get_resource( pld.msg.author.id, 'currency') current_kud = current_kud.current if current_kud >= amount: await cmd.db.del_resource( pld.msg.author.id, 'currency', amount, cmd.name, pld.msg) await cmd.db.add_resource( target.id, 'currency', amount, cmd.name, pld.msg, False) response = GenericResponse( f'Transferred {amount} to {target.display_name}.' ).ok() else: response = discord.Embed( color=0xa7d28b, title='💸 You don\'t have that much.') else: response = GenericResponse( 'Transaction declined by Chamomile.').error() else: response = GenericResponse('Invalid amount.').error() else: response = GenericResponse( 'Can\'t give currency to bots.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse('Missing arguments.').error() else: response = GenericResponse('Nothing inputted.').error() await pld.msg.channel.send(embed=response)
async def voicekick(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).kick_members: target = get_broad_target(pld) if target: if cmd.bot.user.id != target.id: if pld.msg.author.id != target.id: above_hier = hierarchy_permit(pld.msg.author, target) is_admin = pld.msg.author.permissions_in( pld.msg.channel).administrator if above_hier or is_admin: above_me = hierarchy_permit(pld.msg.guild.me, target) if above_me: if target.voice: tvc = target.voice.channel tempvc = discord.utils.find( lambda x: x.name == 'Kick Hall', pld.msg.guild.channels) if not tempvc: tempvc = await pld.msg.guild.create_voice_channel( 'Kick Hall') await target.move_to(tempvc) await tempvc.delete() remove_title = f'👢 {target.name} has been removed from {tvc.name}.' response = discord.Embed(color=0xc1694f, title=remove_title) else: response = GenericResponse( f'{target.name} is not in a voice channel.' ).error() else: response = GenericResponse( 'Target is above my highest role.').denied() else: response = GenericResponse( 'Can\'t kick someone equal or above you.').denied( ) else: response = GenericResponse( 'You can\'t kick yourself.').error() else: response = GenericResponse('I can\'t kick myself.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse( 'Access Denied. Kick permissions needed.').denied() await pld.msg.channel.send(embed=response)
async def unblockextensions(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).manage_guild: if pld.args: blocked_words = pld.settings.get('blocked_extensions') if blocked_words is None: blocked_words = [] removed_words = [] if pld.args[-1].lower() == '--all': removed_words = blocked_words blocked_words = [] else: for word in pld.args: word = word.lstrip('.') if word.lower() in blocked_words: blocked_words.remove(word.lower()) removed_words.append(word.lower()) await cmd.db.set_guild_settings(pld.msg.guild.id, 'blocked_extensions', blocked_words) if removed_words: response = GenericResponse( f'I have removed {len(removed_words)} from the extension blacklist.' ).ok() else: response = GenericResponse( 'No extensions were removed.').info() else: response = GenericResponse('Nothing inputted.').error() else: response = GenericResponse( 'Access Denied. Manage Server needed.').denied() await pld.msg.channel.send(embed=response)