-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tricities-dev/feature/vertex-bot-environments
Info about bot environments, added configuration parsing, tests for bot startup
- Loading branch information
Showing
4 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Vertex | ||
|
||
A Discord bot for the best Discord community out there, TriDev. Vertex comes jam packed with features that make your community come alive. Curl up by a nice Flame War Friday, and enjoy the ride | ||
|
||
## Getting Started | ||
|
||
1. Install the Rust toolchain for your system: https://www.rust-lang.org/learn/get-started | ||
2. Open an issue for @jaketothepast to add you to the Discord developer team. | ||
3. Compile and run the bot locally, with the correct Discord bot token. | ||
|
||
## Running the Bot | ||
|
||
1. Go to Discord developer portal | ||
2. Create a new application | ||
3. Create a new bot user | ||
4. Generate the invite link. | ||
5. Add the bot to your server with the link. | ||
6. Use the bot token as an environment variable `BOT_TOKEN` to start the app | ||
7. Start the bot, profit! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,57 @@ | ||
use discord::Discord; | ||
use clap::Parser; | ||
use dotenv::dotenv; | ||
|
||
extern crate discord; | ||
|
||
// TODO: Better validation of Discord token. | ||
const BOT_TOKEN_LENGTH: usize = 72; | ||
|
||
/// Tri-Cities Vertex Discord Bot | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about)] | ||
pub struct Config { | ||
/// Your bot token you got from Discord Developer portal. | ||
#[arg(short, long, env("BOT_TOKEN"))] | ||
pub bot_token: String | ||
} | ||
|
||
impl Config { | ||
pub fn from_env_and_args() -> Self { | ||
dotenv().ok(); | ||
Self::parse() | ||
} | ||
} | ||
|
||
fn get_discord(bot_token: &str) -> Discord { | ||
if bot_token.len() < BOT_TOKEN_LENGTH { | ||
panic!("invalid bot token"); | ||
} | ||
|
||
return match Discord::from_bot_token(bot_token) { | ||
Ok(discord) => discord, | ||
Err(err) => panic!("error happened: {}", err) | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let discord = Discord::from_bot_token("my_token"); | ||
let cfg = Config::from_env_and_args(); | ||
let discord = get_discord(cfg.bot_token.as_str()); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::get_discord; | ||
|
||
#[test] | ||
#[should_panic] | ||
fn invalid_bot_token_errors() { | ||
get_discord("invalid"); | ||
} | ||
|
||
#[test] | ||
fn valid_bot_token_no_error() { | ||
// Our only validation rule right now is length | ||
get_discord("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | ||
} | ||
} |