Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining Bot ID #229

Open
b00f opened this issue Jan 1, 2025 · 0 comments
Open

Defining Bot ID #229

b00f opened this issue Jan 1, 2025 · 0 comments

Comments

@b00f
Copy link
Contributor

b00f commented Jan 1, 2025

This proposal aims to simplify Pagu by introducing a Bot Identifier. Let’s examine the current challenges:


Problems

  1. Multiple Binaries
    Pagu compiles separately for each platform. For instance, we have binaries like pagu_discord, pagu_telegram, etc.
    It would be advantageous if Pagu could operate on all platforms using a single, uniform binary.

  2. Multiple Configurations
    Each bot requires a separate configuration file, even though most settings are identical. For example, pagu_discord_staging and pagu_discord_mainnet share nearly all the same configurations, differing only in their Discord tokens.

  3. Complicated Command Definitions
    Commands are tied to specific bots. For example, the Faucet command is used to distribute test coins to developers on the testnet and should only operate on Discord's testnet. To achieve this, the PlatformID and Target are defined per command. For the Faucet command, the platform is set to Discord, and the target is set to Testnet.


Solutions

The issues above can be addressed by defining a Bot ID. This Bot ID acts as an enumerator with the following values:

type BotID int

const (
   BotID_CLI_Mainnet       BotID = 1 //nolint // underscores used for BotID
   BotID_CLI_Testnet       BotID = 2 //nolint // underscores used for BotID
   BotID_Discord_Mainnet   BotID = 3 //nolint // underscores used for BotID
   BotID_Discord_Staging   BotID = 4 //nolint // underscores used for BotID
   BotID_Discord_Moderator BotID = 5 //nolint // underscores used for BotID
   BotID_Discord_Testnet   BotID = 6 //nolint // underscores used for BotID
   BotID_Telegram_Mainnet  BotID = 7 //nolint // underscores used for BotID
)

Defining the Bot ID enables us to create a global configuration file. An example of such a configuration is:

List of Pactus nodes that Pagu can connect to for retrieving information about the Pactus network.
# These nodes must have public gRPC endpoints.
nodes:
  mainnet:
    - "bootstrap1.pactus.org:50051"
    - "bootstrap2.pactus.org:50051"
    - "bootstrap3.pactus.org:50051"
    - "bootstrap4.pactus.org:50051"
  testnet:
    - "testnet1.pactus.org:50051"
    - "testnet2.pactus.org:50051"
    - "testnet3.pactus.org:50051"
    - "testnet4.pactus.org:50051"

# Wallet configuration
wallet:
  mainnet-full:
    address: pc1... # Wallet address for transactions
    path: ./config/wallet.sample.full # Path to wallet file
    password: # Wallet file password

  mainnet-neutered:
    address: pc1... 
    path: ./config/wallet.sample.neutered

  testnet:
    address: tpc1...
    path: ./config/wallet.sample.testnet
    password: # Wallet file password

# Phoenix (TestNet) configuration
phoenix:
  faucet_amount: 5 # Amount of coins sent when the faucet is used

# Database configuration
database:
  url: "sqlite:db.sqlite" # Database type and connection string

# Discord integration configuration
discord:
  mainnet:
    guild_id:
    token:
  staging:
    guild_id:
    token:
  moderator:
    guild_id:
    token:
  testnet:
    guild_id:
    token:

# Telegram integration configuration
telegram:
  mainnet:
    bot_token:

# Logger configuration
logger:
  level: "info" # Logging level (debug, info, warn, error, or fatal)
  filename: "pagu.log" # Log file name
  max_size: 10 # Maximum log file size (MB)
  max_backups: 10 # Maximum backup log files to retain
  compress: true # Compress old log files
  targets: [file, console] # Logging targets (file, console, or both)

Given this global configuration and a Bot ID, we can generate the corresponding configuration for each bot. For example, using the moderator Bot ID, we can select the mainnet nodes, the Discord ID of the moderator, and the neutered wallet configuration to build the bot-specific configuration.

Command Definition

Using BotID, we can simplify command definitions by specifying the set of BotIDs that can execute a given command. For example, for the Faucet command, we can simply assign BotID_CLI_Testnet and BotID_Discord_Testnet.


Direct Consequences

This refactor allows us to have a single binary for all platforms. To start Pagu, the following command can be used:

./pagu --global-config <PATH-TO-GLOBAL-CONFIG> --bot-id=<BOT-ID>

This streamlined approach simplifies the architecture, reduces redundancy, and enhances maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant