Skip to content

Commit

Permalink
Merge pull request #17 from BeanstalkFarms/sk/feat/basin-wells
Browse files Browse the repository at this point in the history
Basin bot updates
  • Loading branch information
soilking authored Jul 15, 2024
2 parents ce34122 + 6d3df1c commit 8788669
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 179 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALCHEMY_ETH_API_KEY=your_alchemy_eth_api_key
DISCORD_BOT_TOKEN=your_discord_bot_token
DISCORD_BASIN_BOT_TOKEN=your_discord_basin_bot_token
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*.log
.DS_Store
.env.dev
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ Included in this repo is a set of bots that disseminate information to Beanstalk
- **Contract Bot** - sends a message detailing each interaction with the Beanstalk contact

### Running locally
First, install the necessary requirements using `pip3 install -r beanstalk-py/requirements.txt`.

To run the bots locally you will need to set several environment variables with your own keys.
Environment variables necessary:
- `ETH_CHAIN_API_KEY`
- `SUBGRAPH_API_KEY`
- `ALCHEMY_ETH_API_KEY`
- `DISCORD_BOT_TOKEN` (`DISCORD_BOT_TOKEN_PROD` for prod application)
- `TELE_BOT_KEY` (`TELEGRAM_BOT_TOKEN_PROD` for prod application)
- `DISCORD_BASIN_BOT_TOKEN` (`DISCORD_BASIN_BOT_TOKEN_PROD` for prod application)
- (`TELEGRAM_BOT_TOKEN_PROD` for prod application)

Create an `.env.dev` file using the provided example and place your varaibles there. Then, execute `./dev.sh <module>`. For example, to run the main set of bots, execute `./dev.sh bots.discord_bot`.
18 changes: 17 additions & 1 deletion bots/discord_basin_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
DISCORD_CHANNEL_ID_TEST = 1117767077420339220
DISCORD_CHANNEL_ID_BEAN_ETH = 1117768417861193819
DISCORD_CHANNEL_ID_DAILY = 1117768293625888868
DISCORD_CHANNEL_ID_WELLS_OTHER = 1257633554427543633


class Channel(Enum):
REPORT = 0
DAILY = 1
BEAN_ETH = 2
WELLS_OTHER = 3


class DiscordClient(discord.ext.commands.Bot):
Expand All @@ -32,11 +34,13 @@ def __init__(self, prod=False):
self._chat_id_report = DISCORD_CHANNEL_ID_TEST
self._chat_id_daily = DISCORD_CHANNEL_ID_DAILY
self._chat_id_bean_eth = DISCORD_CHANNEL_ID_BEAN_ETH
self._chat_id_other_wells = DISCORD_CHANNEL_ID_WELLS_OTHER
logging.info("Configured as a production instance.")
else:
self._chat_id_report = DISCORD_CHANNEL_ID_TEST
self._chat_id_daily = DISCORD_CHANNEL_ID_TEST
self._chat_id_bean_eth = DISCORD_CHANNEL_ID_TEST
self._chat_id_other_wells = DISCORD_CHANNEL_ID_TEST
logging.info("Configured as a staging instance.")

self.msg_queue = []
Expand All @@ -57,6 +61,11 @@ def __init__(self, prod=False):
)
self.well_monitor_bean_eth.start()

self.well_monitor_all = util.AllWellsMonitor(
self.send_msg_wells_other, [BEAN_ETH_WELL_ADDR], discord=True, prod=prod, dry_run=False
)
self.well_monitor_all.start()

# Ignore exceptions of this type and retry. Note that no logs will be generated.
# Ignore base class, because we always want to reconnect.
# https://discordpy.readthedocs.io/en/latest/api.html#discord.ClientUser.edit
Expand Down Expand Up @@ -84,13 +93,18 @@ def send_msg_bean_eth(self, text):
"""Send a message through the Discord bot in the bean eth well channel."""
self.msg_queue.append((Channel.BEAN_ETH, text))

def send_msg_wells_other(self, text):
"""Send a message through the Discord bot in the other wells channel."""
self.msg_queue.append((Channel.WELLS_OTHER, text))

async def on_ready(self):
self._channel_report = self.get_channel(self._chat_id_report)
self._channel_daily = self.get_channel(self._chat_id_daily)
self._channel_bean_eth = self.get_channel(self._chat_id_bean_eth)
self._channel_wells_other = self.get_channel(self._chat_id_other_wells)

logging.info(
f"Discord channels are {self._channel_report}, {self._channel_daily}, {self._channel_bean_eth}"
f"Discord channels are {self._channel_report}, {self._channel_daily}, {self._channel_bean_eth}, {self._chat_id_other_wells}"
)

# Guild IDs for all servers this bot is in.
Expand Down Expand Up @@ -138,6 +152,8 @@ async def send_queued_messages(self):
await self._channel_daily.send(msg)
elif channel is Channel.BEAN_ETH:
await self._channel_bean_eth.send(msg)
elif channel is Channel.WELLS_OTHER:
await self._channel_wells_other.send(msg)
else:
logging.error("Unknown channel seen in msg queue: {channel}")
self.msg_queue = self.msg_queue[1:]
Expand Down
5 changes: 5 additions & 0 deletions bots/telegram_basin_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def __init__(self, token, prod=False):
)
self.well_monitor_bean_eth.start()

self.well_monitor_all = util.AllWellsMonitor(
self.send_msg, [BEAN_ETH_WELL_ADDR], discord=False, prod=prod, dry_run=False
)
self.well_monitor_all.start()

def send_msg(self, msg):
# Ignore empty messages.
if not msg:
Expand Down
Loading

0 comments on commit 8788669

Please sign in to comment.