Skip to content

Commit

Permalink
Merge pull request #2 from milkyskies/feat/move-client-id-to-env-vars
Browse files Browse the repository at this point in the history
Move test client ID to environment variables
  • Loading branch information
Cyteon authored Jul 30, 2024
2 parents a97255d + 1e13288 commit 219b611
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TEST_BOT_TOKEN=
TEST_BOT_CLIENT_ID=
21 changes: 18 additions & 3 deletions test/discord_gleam_test.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import example_bot
import gleam/erlang/os
import gleam/io
import gleam/result

pub fn main() {
case os.get_env("TEST_BOT_TOKEN") {
Ok(token) -> example_bot.main(token)
Error(_) -> io.println("Token not found :c")
case
{
use token <- result.try(get_env("TEST_BOT_TOKEN"))
use client_id <- result.try(get_env("TEST_BOT_CLIENT_ID"))

Ok(example_bot.main(token, client_id))
}
{
Ok(_) -> Nil
Error(msg) -> io.println(msg)
}
}

fn get_env(var: String) -> Result(String, String) {
case os.get_env(var) {
Ok(value) -> Ok(value)
Error(_) -> Error("Environment variable " <> var <> " not found")
}
}
4 changes: 2 additions & 2 deletions test/example_bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import gleam/list
import gleam/string
import logging

pub fn main(token: String) {
pub fn main(token: String, client_id: String) {
logging.configure()
logging.set_level(logging.Debug)

Expand All @@ -28,7 +28,7 @@ pub fn main(token: String) {
],
)

discord_gleam.register_commands(bot, "1262338071874244650", [test_cmd])
discord_gleam.register_commands(bot, client_id, [test_cmd])

discord_gleam.run(bot, [event_handler])
}
Expand Down

0 comments on commit 219b611

Please sign in to comment.