Files
OpenBB/discordbot/menus/menu.py
teh_coderer d8279adcbf Feature/discord slash commands (#1293)
* SlashCmdsPlotlyDf2img

- discord.py
+ disnake
+ all cmds converted to / cmds
- tabulate
+ switch to df2img
+ plots to plotly

+++++

* add settings

* Update run_discordbot.py

* Update config_discordbot.py

* Fixing black

* switch to yfinance

and fix indention on min/max strike

* + logger, - testing prints

added logger's I was missing and removed old print testing code

* final tradier removal + fixes

+ added past_days arg to /cc
- removed tradier
+ noticed had accidently removed if df.empty from economy cmds. fixed

* linting + renamed cogs folder to cmds

* Update run_discordbot.py

* Update run_discordbot.py

* remove cachetools

* linting

* pylint

* Made file retrieval global

* Updated dependencies

* updates

+added /btc,eth,sol
-removed /earnings
+updated README.md
+ added SLASH_TESTING_SERVERS in cfg for instant cmds when testing

* Made slash_testing an env variable

* Improved slash_testing handling

* Fix testserver

* FIxed test_servers

* Fixed testing_servers

* updates

+ vwap on /cc
+ fixed expiry_autocomp  exceeding 25 option limit on SPY dates
+ opt-hist changed to scatter and with greeks now
+ opt-cc-hist the old way of plotting with candlesticks chart

* remove import

* update Readme

* width fix

* replacement of tradier for yf

* title fix

Co-authored-by: Colin Delahunty <colin99delahunty@gmail.com>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
2022-02-03 21:20:56 -05:00

124 lines
3.7 KiB
Python

import time
from typing import List
import config_discordbot as cfg
import disnake
from disnake.ext import commands
bot = commands.Bot()
startTime = time.time()
class Menu(disnake.ui.View):
def __init__(
self, embeds: List[disnake.Embed], options: List[disnake.SelectOption]
):
super().__init__(timeout=None)
# Sets the embed list variable.
self.embeds = embeds
self.options = options
# Current embed number.
self.embed_count = 0
# Disables previous page button by default.
self.prev_page.disabled = True
# Sets the footer of the embeds with their respective page numbers.
self.count = 0
self.set_link_button()
for opt in options:
self.selector.append_option(opt) # pylint: disable=E1101
for i, embed in enumerate(self.embeds):
embed.set_footer(
text=f"Page {i + 1} of {len(self.embeds)}",
icon_url=cfg.AUTHOR_ICON_URL,
)
def set_link_button(self) -> None:
if not hasattr(self, "link_button"):
self.link_button = disnake.ui.Button(
style=disnake.ButtonStyle.url,
url="https://github.com/GamestonkTerminal/GamestonkTerminal",
label="Site",
row=0,
)
self.add_item(self.link_button)
self.link_button.label = "Site"
self.count += 1
@disnake.ui.select(
placeholder="Page Select",
custom_id="select",
row=1,
)
async def selector(
self,
select: disnake.ui.Select,
inter: disnake.MessageInteraction,
) -> None:
self.set_link_button()
s = ""
str1 = s.join(select.values)
ind = int(str1)
self.embed_count = ind
self.next_page.disabled = False
self.prev_page.disabled = False
if self.embed_count == 0:
self.prev_page.disabled = True
if self.embed_count == len(self.embeds) - 1:
self.next_page.disabled = True
print(select.values)
await inter.response.edit_message(embed=self.embeds[ind], view=self)
@disnake.ui.button(
label="Previous page",
emoji="<a:leftarrow:929686892339937371>",
style=disnake.ButtonStyle.red,
custom_id="persistent_view:prevpage",
)
async def prev_page( # pylint: disable=W0613
self,
button: disnake.ui.Button,
interaction: disnake.MessageInteraction,
):
# Decrements the embed count.
self.embed_count -= 1
# Gets the embed object.
embed = self.embeds[self.embed_count]
# Enables the next page button and disables the previous page button if we're on the first embed.
self.next_page.disabled = False
if self.embed_count == 0:
self.prev_page.disabled = True
await interaction.response.edit_message(embed=embed, view=self)
@disnake.ui.button(
label="Next page",
emoji="<a:rightarrow:929686891891155006>",
style=disnake.ButtonStyle.red,
custom_id="persistent_view:nextpage",
)
async def next_page( # pylint: disable=W0613
self,
button: disnake.ui.Button,
interaction: disnake.MessageInteraction,
):
# Increments the embed count.
self.embed_count += 1
# Gets the embed object.
embed = self.embeds[self.embed_count]
# Enables the previous page button and disables the next page button if we're on the last embed.
self.prev_page.disabled = False
if self.embed_count == len(self.embeds) - 1:
self.next_page.disabled = True
await interaction.response.edit_message(embed=embed, view=self)