mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-04-30 06:24:27 +02:00
feat: move DISCORD_AUTHORIZATION_TOKEN
to .env
This commit is contained in:
parent
3c14cbe6a4
commit
42098b9db5
2
.env.example
Normal file
2
.env.example
Normal file
@ -0,0 +1,2 @@
|
||||
# The Discord authorization token for the bot, requires the MESSAGE_CONTENT intent
|
||||
DISCORD_AUTHORIZATION_TOKEN=
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
configuration.json
|
||||
configuration.json
|
||||
.env
|
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -152,6 +152,12 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.31"
|
||||
@ -678,6 +684,7 @@ name = "revanced-discord-bot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dotenv",
|
||||
"log",
|
||||
"regex",
|
||||
"serde",
|
||||
|
@ -18,6 +18,7 @@ panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
dotenv = "0.15"
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.0", features = ["rt-multi-thread"] }
|
||||
log = "0.4"
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"$schema": "./configuration.schema.json",
|
||||
"discord_authorization_token": "",
|
||||
"administrators": {
|
||||
"roles": [0],
|
||||
"users": [0]
|
||||
|
@ -4,12 +4,7 @@
|
||||
"title": "Configuration schema",
|
||||
"description": "The Revanced Discord bot configuration schema.",
|
||||
"type": "object",
|
||||
"required": ["discord_authorization_token"],
|
||||
"properties": {
|
||||
"discord_authorization_token": {
|
||||
"type": "string",
|
||||
"description": "The authorization token for the Discord bot."
|
||||
},
|
||||
"administrators": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
18
src/main.rs
18
src/main.rs
@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
|
||||
@ -223,22 +224,37 @@ impl EventHandler for Handler {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Initialize the logging framework.
|
||||
log::set_logger(&LOGGER)
|
||||
.map(|()| log::set_max_level(LevelFilter::Warn))
|
||||
.expect("Could not set logger.");
|
||||
|
||||
// Set up the configuration.
|
||||
let configuration = load_configuration();
|
||||
|
||||
// Get the Discord authorization token.
|
||||
dotenv::dotenv().ok();
|
||||
let token = match env::vars().find(|(key, _)| key == "DISCORD_AUTHORIZATION_TOKEN") {
|
||||
Some((_, value)) => value,
|
||||
None => {
|
||||
error!("Environment variable DISCORD_AUTHORIZATION_TOKEN unset.");
|
||||
std::process::exit(1);
|
||||
},
|
||||
};
|
||||
|
||||
// Create the Discord bot client.
|
||||
let mut client = Client::builder(
|
||||
&configuration.discord_authorization_token,
|
||||
&token,
|
||||
GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT,
|
||||
)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Failed to create client");
|
||||
|
||||
// Save the configuration.
|
||||
client.data.write().await.insert::<BotConfiguration>(Arc::new(RwLock::new(configuration)));
|
||||
|
||||
// Start the Discord bot.
|
||||
if let Err(why) = client.start().await {
|
||||
error!("{:?}", why);
|
||||
} else {
|
||||
|
@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
pub struct Configuration {
|
||||
pub discord_authorization_token: String,
|
||||
pub administrators: Administrators,
|
||||
pub thread_introductions: Vec<Introduction>,
|
||||
pub message_responses: Vec<MessageResponse>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user