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=
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
configuration.json
|
configuration.json
|
||||||
|
.env
|
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -152,6 +152,12 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenv"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
version = "0.8.31"
|
version = "0.8.31"
|
||||||
@ -678,6 +684,7 @@ name = "revanced-discord-bot"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"dotenv",
|
||||||
"log",
|
"log",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -18,6 +18,7 @@ panic = "abort"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
dotenv = "0.15"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tokio = { version = "1.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.0", features = ["rt-multi-thread"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./configuration.schema.json",
|
"$schema": "./configuration.schema.json",
|
||||||
"discord_authorization_token": "",
|
|
||||||
"administrators": {
|
"administrators": {
|
||||||
"roles": [0],
|
"roles": [0],
|
||||||
"users": [0]
|
"users": [0]
|
||||||
|
@ -4,12 +4,7 @@
|
|||||||
"title": "Configuration schema",
|
"title": "Configuration schema",
|
||||||
"description": "The Revanced Discord bot configuration schema.",
|
"description": "The Revanced Discord bot configuration schema.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["discord_authorization_token"],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"discord_authorization_token": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The authorization token for the Discord bot."
|
|
||||||
},
|
|
||||||
"administrators": {
|
"administrators": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -1,3 +1,4 @@
|
|||||||
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
|
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
|
||||||
@ -223,22 +224,37 @@ impl EventHandler for Handler {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
// Initialize the logging framework.
|
||||||
log::set_logger(&LOGGER)
|
log::set_logger(&LOGGER)
|
||||||
.map(|()| log::set_max_level(LevelFilter::Warn))
|
.map(|()| log::set_max_level(LevelFilter::Warn))
|
||||||
.expect("Could not set logger.");
|
.expect("Could not set logger.");
|
||||||
|
|
||||||
|
// Set up the configuration.
|
||||||
let configuration = load_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(
|
let mut client = Client::builder(
|
||||||
&configuration.discord_authorization_token,
|
&token,
|
||||||
GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT,
|
GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT,
|
||||||
)
|
)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create client");
|
.expect("Failed to create client");
|
||||||
|
|
||||||
|
// Save the configuration.
|
||||||
client.data.write().await.insert::<BotConfiguration>(Arc::new(RwLock::new(configuration)));
|
client.data.write().await.insert::<BotConfiguration>(Arc::new(RwLock::new(configuration)));
|
||||||
|
|
||||||
|
// Start the Discord bot.
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
error!("{:?}", why);
|
error!("{:?}", why);
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize)]
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
pub discord_authorization_token: String,
|
|
||||||
pub administrators: Administrators,
|
pub administrators: Administrators,
|
||||||
pub thread_introductions: Vec<Introduction>,
|
pub thread_introductions: Vec<Introduction>,
|
||||||
pub message_responses: Vec<MessageResponse>,
|
pub message_responses: Vec<MessageResponse>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user