async def should_cmdr_be_on_kos(self, req_id, cmdr_name, msg): """ Send a message with buttons to the user asking if the cmdr should be reported. Args: req_id: The request id. cmdr_name: The name of the commander being reported. msg: The original message with the channel/author reporting the cmdr. Returns: A dictionary with the information to add user to KOS. Format follows: { 'add': True | False, # If True, add to the KOS. Otherwise, take no action. 'is_friendly': True | False, # If the user is friendly or hostile, 'cmdr': String, # The name of cmdr. 'reason': String, # Reason to add cmdr, 'squad': String, # The squadron of the cmdr if known. } """ components = [ dcom.Button(label=BUT_FRIENDLY, style=dcom.ButtonStyle.green), dcom.Button(label=BUT_HOSTILE, style=dcom.ButtonStyle.red), dcom.Button(label=BUT_CANCEL, style=dcom.ButtonStyle.grey), ] text = f"Should the CMDR {cmdr_name} be added as friendly or hostile?" sent = await cog.util.BOT.send_message(msg.channel, text, components=components) self.waiting_messages[req_id] = sent check = functools.partial(check_interaction_response, msg.author, sent) inter = await cog.util.BOT.wait_for('button_click', check=check) # Approved update kos_info = copy.deepcopy(KOS_INFO_PROTO) kos_info['cmdr'] = cmdr_name if inter.component.label == BUT_CANCEL: response = "This report will be cancelled. Have a nice day!" else: kos_info.update({ 'add': True, 'is_friendly': inter.component.label == BUT_FRIENDLY, 'reason': f"Manual report after a !whois in {msg.channel} by cmdr {msg.author}", }) response = """You selected {} Leadership will review your report. Thank you.""".format(inter.component.label) await inter.send(response) await self.delete_waiting_message(req_id) return kos_info
def return_buttons(self) -> list[list[discord_components.Button]]: return [[ discord_components.Button(id="lfg_join", style=discord_components.ButtonStyle.green, label="Join", emoji=self._join_emoji, disabled=len(self.joined_members) >= self.max_joined_members), discord_components.Button(id="lfg_leave", style=discord_components.ButtonStyle.red, label="Leave", emoji=self._leave_emoji), discord_components.Button(id="lfg_backup", style=discord_components.ButtonStyle.blue, label="Backup", emoji=self._backup_emoji), ]]
async def pagination(cols, ctx): current = 0 components = [[ discord_components.Button(label="Prev", id="back", style=discord_components.ButtonStyle.red), discord_components.Button( label=f"Page {int(cols.index(cols[current]))}/{len(cols)-1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button(label="Next", id="front", style=discord_components.ButtonStyle.green), ]] main_message = await ctx.send(embed=cols[current], components=components) while True: # Try and except blocks to catch timeout and break try: interaction = await gst_bot.wait_for( "button_click", check=lambda i: i.component.id in ["back", "front" ], # You can add more timeout=30.0, # 30 seconds of inactivity ) # Getting the right list index if interaction.component.id == "back": current -= 1 elif interaction.component.id == "front": current += 1 # If its out of index, go back to start / end if current == len(cols): current = 0 elif current < 0: current = len(cols) - 1 # Edit to new page + the center counter changes components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.red, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols)-1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, ), ]] await interaction.edit_origin(embed=cols[current], components=components) except asyncio.TimeoutError: # Disable and get outta here components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols)-1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) break
async def on_reaction_add(reaction, user): if user == ctx.message.author and str( reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": if cfg.DEBUG: print("Reaction selected: 0") if current == 0: await view_command(ctx, ticker) elif current == 1: await rsi_command(ctx, ticker) elif current == 2: await adosc_command(ctx, ticker) elif reaction.emoji == "1️⃣": if cfg.DEBUG: print("Reaction selected: 1") if current == 0: await summary_command(ctx, ticker) elif current == 1: await stoch_command(ctx, ticker) elif current == 2: await obv_command(ctx, ticker) elif reaction.emoji == "2️⃣": if cfg.DEBUG: print("Reaction selected: 2") if current == 0: await recom_command(ctx, ticker) elif current == 1: await fisher_command(ctx, ticker) elif current == 2: await fib_command(ctx, ticker) elif reaction.emoji == "3️⃣": if cfg.DEBUG: print("Reaction selected: 3") if current == 0: await ema_command(ctx, ticker) elif current == 1: await cg_command(ctx, ticker) elif reaction.emoji == "4️⃣": if cfg.DEBUG: print("Reaction selected: 4") if current == 0: await sma_command(ctx, ticker) elif current == 1: await adx_command(ctx, ticker) elif reaction.emoji == "5️⃣": if cfg.DEBUG: print("Reaction selected: 5") if current == 0: await wma_command(ctx, ticker) elif current == 1: await aroon_command(ctx, ticker) elif reaction.emoji == "6️⃣": if cfg.DEBUG: print("Reaction selected: 6") if current == 0: await hma_command(ctx, ticker) elif current == 1: await bbands_command(ctx, ticker) elif reaction.emoji == "7️⃣": if cfg.DEBUG: print("Reaction selected: 7") if current == 0: await zlma_command(ctx, ticker) elif current == 1: await donchian_command(ctx, ticker) elif reaction.emoji == "8️⃣": if cfg.DEBUG: print("Reaction selected: 8") if current == 0: await cci_command(ctx, ticker) elif current == 1: await kc_command(ctx, ticker) elif reaction.emoji == "9️⃣": if cfg.DEBUG: print("Reaction selected: 9") if current == 0: await macd_command(ctx, ticker) elif current == 1: await ad_command(ctx, ticker) for emoji in emoji_list: await main_message.remove_reaction( emoji, ctx.bot.user) components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) return
async def ta(self, ctx: discord.ext.commands.Context, ticker=""): """Stocks Context - Shows Technical Analysis Menu Run `!help TechnicalAnalysisCommands` to see the list of available commands. Returns ------- Sends a message to the discord user with the commands from the stocks.ta context. The user can then select a reaction to trigger a command. """ if cfg.DEBUG: print(f"!stocks.ta {ticker}") cols_temp = [] cols = [] if ticker == "": embed = discord.Embed( title="ERROR Stocks: Technical Analysis (TA) Menu", colour=cfg.COLOR, description="A stock ticker is required", ) embed.set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) await ctx.send(embed=embed) return stock = discordbot.helpers.load(ticker, datetime.now() - timedelta(days=365)) if stock.empty: embed = discord.Embed( title="ERROR Stocks: Technical Analysis (TA) Menu", colour=cfg.COLOR, description="Enter a valid stock ticker", ) embed.set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) await ctx.send(embed=embed) return text = ( f"0️⃣ !stocks.ta.view {ticker}\n" f"1️⃣ !stocks.ta.summary {ticker}\n" f"2️⃣ !stocks.ta.recom {ticker}\n" f"3️⃣ !stocks.ta.ema {ticker} <WINDOW> <OFFSET> <START> <END>\n" f"4️⃣ !stocks.ta.sma {ticker} <WINDOW> <OFFSET> <START> <END>\n" f"5️⃣ !stocks.ta.wma {ticker} <WINDOW> <OFFSET> <START> <END>\n" f"6️⃣ !stocks.ta.hma {ticker} <WINDOW> <OFFSET> <START> <END>\n" f"7️⃣ !stocks.ta.zlma {ticker} <WINDOW> <OFFSET> <START> <END>\n" f"8️⃣ !stocks.ta.cci {ticker} <LENGTH> <SCALAR> <START> <END>\n" f"9️⃣ !stocks.ta.macd {ticker} <FAST> <SLOW> <SIGNAL> <START> <END>" ) cols_temp.append(text) text = ( f"0️⃣ !stocks.ta.rsi {ticker} <LENGTH> <SCALAR> <DRIFT> <START> <END>\n" f"1️⃣ !stocks.ta.stoch {ticker} <FAST_K> <SLOW_D> <SLOW_K> <START> <END>\n" f"2️⃣ !stocks.ta.fisher {ticker} <LENGTH> <START> <END>\n" f"3️⃣ !stocks.ta.cg {ticker} <LENGTH> <START> <END>\n" f"4️⃣ !stocks.ta.adx {ticker} <LENGTH> <SCALAR> <DRIFT> <START> <END>\n" f"5️⃣ !stocks.ta.aroon {ticker} <LENGTH> <SCALAR> <START> <END>\n" f"6️⃣ !stocks.ta.bbands {ticker} <LENGTH> <SCALAR> <MA_MODE> <START> <END>\n" f"7️⃣ !stocks.ta.donchian {ticker} <LOWER_LENGTH> <UPPER_LENGTH> <START> <END>\n" f"8️⃣ !stocks.ta.kc {ticker} <LENGTH> <SCALAR> <MA_MODE> <START> <END>\n" f"9️⃣ !stocks.ta.ad {ticker} <OPEN> <START> <END>") cols_temp.append(text) text = ( f"0️⃣ !stocks.ta.adosc {ticker} <OPEN> <FAST> <SLOW> <START> <END>\n" f"1️⃣ !stocks.ta.obv {ticker} <START> <END>\n" f"2️⃣ !stocks.ta.fib {ticker} <START> <END>\n") cols_temp.append(text) for col in cols_temp: cols.append( discord.Embed( description=col, colour=cfg.COLOR, title="Stocks: Technical Analysis (TA) Menu", ).set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, )) emoji_list = [ "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", ] current = 0 components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.red), discord_components.Button( label=f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green), ]] main_message = await ctx.send(embed=cols[current], components=components) for emoji in emoji_list: await main_message.add_reaction(emoji) while True: # Try and except blocks to catch timeout and break try: interaction = await gst_bot.wait_for( "button_click", check=lambda i: i.component.id in ["back", "front" ], # You can add more timeout=cfg.MENU_TIMEOUT, # Some seconds of inactivity ) # Getting the right list index if interaction.component.id == "back": current -= 1 elif interaction.component.id == "front": current += 1 # If its out of index, go back to start / end if current == len(cols): current = 0 elif current < 0: current = len(cols) - 1 # Edit to new page + the center counter changes components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.red, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, ), ]] await interaction.edit_origin(embed=cols[current], components=components) # pylint: disable=too-many-branches @gst_bot.event async def on_reaction_add(reaction, user): if user == ctx.message.author and str( reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": if cfg.DEBUG: print("Reaction selected: 0") if current == 0: await view_command(ctx, ticker) elif current == 1: await rsi_command(ctx, ticker) elif current == 2: await adosc_command(ctx, ticker) elif reaction.emoji == "1️⃣": if cfg.DEBUG: print("Reaction selected: 1") if current == 0: await summary_command(ctx, ticker) elif current == 1: await stoch_command(ctx, ticker) elif current == 2: await obv_command(ctx, ticker) elif reaction.emoji == "2️⃣": if cfg.DEBUG: print("Reaction selected: 2") if current == 0: await recom_command(ctx, ticker) elif current == 1: await fisher_command(ctx, ticker) elif current == 2: await fib_command(ctx, ticker) elif reaction.emoji == "3️⃣": if cfg.DEBUG: print("Reaction selected: 3") if current == 0: await ema_command(ctx, ticker) elif current == 1: await cg_command(ctx, ticker) elif reaction.emoji == "4️⃣": if cfg.DEBUG: print("Reaction selected: 4") if current == 0: await sma_command(ctx, ticker) elif current == 1: await adx_command(ctx, ticker) elif reaction.emoji == "5️⃣": if cfg.DEBUG: print("Reaction selected: 5") if current == 0: await wma_command(ctx, ticker) elif current == 1: await aroon_command(ctx, ticker) elif reaction.emoji == "6️⃣": if cfg.DEBUG: print("Reaction selected: 6") if current == 0: await hma_command(ctx, ticker) elif current == 1: await bbands_command(ctx, ticker) elif reaction.emoji == "7️⃣": if cfg.DEBUG: print("Reaction selected: 7") if current == 0: await zlma_command(ctx, ticker) elif current == 1: await donchian_command(ctx, ticker) elif reaction.emoji == "8️⃣": if cfg.DEBUG: print("Reaction selected: 8") if current == 0: await cci_command(ctx, ticker) elif current == 1: await kc_command(ctx, ticker) elif reaction.emoji == "9️⃣": if cfg.DEBUG: print("Reaction selected: 9") if current == 0: await macd_command(ctx, ticker) elif current == 1: await ad_command(ctx, ticker) for emoji in emoji_list: await main_message.remove_reaction( emoji, ctx.bot.user) components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) return except asyncio.TimeoutError: # Disable and get outta here components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) if cfg.DEBUG: embed = discord.Embed( description="Error timeout - you snooze you lose! 😋", colour=cfg.COLOR, title="TIMEOUT Stocks: Technical Analysis (TA) Menu", ).set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) await ctx.send(embed=embed) for emoji in emoji_list: await main_message.remove_reaction(emoji, ctx.bot.user) break
async def on_reaction_add(reaction, user): if user == ctx.message.author and str( reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": if cfg.DEBUG: print("Reaction selected: 0") if current == 0: await overview_command(ctx) elif current == 1: await metals_command(ctx) elif reaction.emoji == "1️⃣": if cfg.DEBUG: print("Reaction selected: 1") if current == 0: await futures_command(ctx) elif current == 1: await meats_command(ctx) elif reaction.emoji == "2️⃣": if cfg.DEBUG: print("Reaction selected: 2") if current == 0: await usbonds_command(ctx) elif current == 1: await grains_command(ctx) elif reaction.emoji == "3️⃣": if cfg.DEBUG: print("Reaction selected: 3") if current == 0: await glbonds_command(ctx) elif current == 1: await softs_command(ctx) elif reaction.emoji == "4️⃣": if cfg.DEBUG: print("Reaction selected: 4") await indices_command(ctx) elif reaction.emoji == "5️⃣": if cfg.DEBUG: print("Reaction selected: 5") await currencies_command(ctx) elif reaction.emoji == "6️⃣": if cfg.DEBUG: print("Reaction selected: 6") await feargreed_command(ctx) elif reaction.emoji == "7️⃣": if cfg.DEBUG: print("Reaction selected: 7") await valuation_command(ctx) elif reaction.emoji == "8️⃣": if cfg.DEBUG: print("Reaction selected: 8") await performance_command(ctx) elif reaction.emoji == "9️⃣": if cfg.DEBUG: print("Reaction selected: 9") await energy_command(ctx) for emoji in emoji_list: await main_message.remove_reaction( emoji, ctx.bot.user) components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) return
async def economy(self, ctx: discord.ext.commands.Context): """Economy Context Menu Run `!help EconomyCommands` to see the list of available commands. Returns ------- Sends a message to the discord user with the commands from the economy context. The user can then select a reaction to trigger a command. """ if cfg.DEBUG: print("!economy") cols_temp = [] cols = [] text = ("0️⃣ !economy.overview\n" "1️⃣ !economy.futures\n" "2️⃣ !economy.usbonds\n" "3️⃣ !economy.glbonds\n" "4️⃣ !economy.indices\n" "5️⃣ !economy.currencies\n" "6️⃣ !economy.feargreed\n" "7️⃣ !economy.valuation <GROUP>\n" "8️⃣ !economy.performance <GROUP>\n" "9️⃣ !economy.energy") cols_temp.append(text) text = ("0️⃣ !economy.metals\n" "1️⃣ !economy.meats\n" "2️⃣ !economy.grains\n" "3️⃣ !economy.softs") cols_temp.append(text) for col in cols_temp: cols.append( discord.Embed( description=col, colour=cfg.COLOR, title="Economy Menu", ).set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, )) emoji_list = [ "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", ] current = 0 components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.red), discord_components.Button( label=f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green), ]] main_message = await ctx.send(embed=cols[current], components=components) for emoji in emoji_list: await main_message.add_reaction(emoji) while True: # Try and except blocks to catch timeout and break try: interaction = await gst_bot.wait_for( "button_click", check=lambda i: i.component.id in ["back", "front" ], # You can add more timeout=cfg.MENU_TIMEOUT, # Some seconds of inactivity ) # Getting the right list index if interaction.component.id == "back": current -= 1 elif interaction.component.id == "front": current += 1 # If its out of index, go back to start / end if current == len(cols): current = 0 elif current < 0: current = len(cols) - 1 # Edit to new page + the center counter changes components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.red, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, ), ]] await interaction.edit_origin(embed=cols[current], components=components) # pylint: disable=too-many-branches @gst_bot.event async def on_reaction_add(reaction, user): if user == ctx.message.author and str( reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": if cfg.DEBUG: print("Reaction selected: 0") if current == 0: await overview_command(ctx) elif current == 1: await metals_command(ctx) elif reaction.emoji == "1️⃣": if cfg.DEBUG: print("Reaction selected: 1") if current == 0: await futures_command(ctx) elif current == 1: await meats_command(ctx) elif reaction.emoji == "2️⃣": if cfg.DEBUG: print("Reaction selected: 2") if current == 0: await usbonds_command(ctx) elif current == 1: await grains_command(ctx) elif reaction.emoji == "3️⃣": if cfg.DEBUG: print("Reaction selected: 3") if current == 0: await glbonds_command(ctx) elif current == 1: await softs_command(ctx) elif reaction.emoji == "4️⃣": if cfg.DEBUG: print("Reaction selected: 4") await indices_command(ctx) elif reaction.emoji == "5️⃣": if cfg.DEBUG: print("Reaction selected: 5") await currencies_command(ctx) elif reaction.emoji == "6️⃣": if cfg.DEBUG: print("Reaction selected: 6") await feargreed_command(ctx) elif reaction.emoji == "7️⃣": if cfg.DEBUG: print("Reaction selected: 7") await valuation_command(ctx) elif reaction.emoji == "8️⃣": if cfg.DEBUG: print("Reaction selected: 8") await performance_command(ctx) elif reaction.emoji == "9️⃣": if cfg.DEBUG: print("Reaction selected: 9") await energy_command(ctx) for emoji in emoji_list: await main_message.remove_reaction( emoji, ctx.bot.user) components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) return except asyncio.TimeoutError: # Disable and get outta here components = [[ discord_components.Button( label="Prev", id="back", style=discord_components.ButtonStyle.green, disabled=True, ), discord_components.Button( label= f"Page {int(cols.index(cols[current]))}/{len(cols) - 1}", id="cur", style=discord_components.ButtonStyle.grey, disabled=True, ), discord_components.Button( label="Next", id="front", style=discord_components.ButtonStyle.green, disabled=True, ), ]] await main_message.edit(components=components) if cfg.DEBUG: embed = discord.Embed( description="Error timeout - you snooze you lose! 😋", colour=cfg.COLOR, title="TIMEOUT Economy Menu", ).set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) await ctx.send(embed=embed) for emoji in emoji_list: await main_message.remove_reaction(emoji, ctx.bot.user) break