@@ -29,15 +29,16 @@ pub(crate) type Result = crate::commands::Result<()>;
29
29
struct Config {
30
30
tags : bool ,
31
31
crates : bool ,
32
+ discord_token : String ,
33
+ mod_id : String ,
34
+ talk_id : String ,
35
+ wg_and_teams_id : Option < String > ,
32
36
}
33
37
34
38
fn init_data ( config : & Config ) -> Result {
35
39
use crate :: schema:: roles;
36
40
info ! ( "Loading data into database" ) ;
37
41
38
- let mod_role = std:: env:: var ( "MOD_ID" ) . map_err ( |_| "MOD_ID env var not found" ) ?;
39
- let talk_role = std:: env:: var ( "TALK_ID" ) . map_err ( |_| "TALK_ID env var not found" ) ?;
40
-
41
42
let conn = DB . get ( ) ?;
42
43
43
44
let upsert_role = |name : & str , role_id : & str | -> Result {
@@ -55,11 +56,14 @@ fn init_data(config: &Config) -> Result {
55
56
. build_transaction ( )
56
57
. read_write ( )
57
58
. run :: < _ , Box < dyn std:: error:: Error > , _ > ( || {
58
- upsert_role ( "mod" , & mod_role) ?;
59
- upsert_role ( "talk" , & talk_role) ?;
59
+ upsert_role ( "mod" , & config. mod_id ) ?;
60
+ upsert_role ( "talk" , & config. talk_id ) ?;
61
+
60
62
if config. tags || config. crates {
61
- let wg_and_teams_role = & std:: env:: var ( "WG_AND_TEAMS_ID" )
62
- . map_err ( |_| "WG_AND_TEAMS_ID env var not found" ) ?;
63
+ let wg_and_teams_role = config
64
+ . wg_and_teams_id
65
+ . as_ref ( )
66
+ . ok_or_else ( || "missing value for field wg_and_teams_id.\n \n If you enabled tags or crates then you need the WG_AND_TEAMS_ID env var." ) ?;
63
67
upsert_role ( "wg_and_teams" , & wg_and_teams_role) ?;
64
68
}
65
69
@@ -70,12 +74,9 @@ fn init_data(config: &Config) -> Result {
70
74
}
71
75
72
76
fn app ( ) -> Result {
73
- info ! ( "starting..." ) ;
74
-
75
77
let config = envy:: from_env :: < Config > ( ) ?;
76
78
77
- let token = std:: env:: var ( "DISCORD_TOKEN" )
78
- . map_err ( |_| "missing environment variable: DISCORD_TOKEN" ) ?;
79
+ info ! ( "starting..." ) ;
79
80
80
81
let _ = db:: run_migrations ( ) ?;
81
82
@@ -122,7 +123,7 @@ fn app() -> Result {
122
123
Ok ( ( ) )
123
124
} ) ;
124
125
125
- let mut client = Client :: new_with_extras ( & token , |e| {
126
+ let mut client = Client :: new_with_extras ( & config . discord_token , |e| {
126
127
e. event_handler ( Messages { cmds } ) ;
127
128
e. raw_event_handler ( Events ) ;
128
129
e
@@ -136,8 +137,8 @@ fn app() -> Result {
136
137
fn main ( ) {
137
138
env_logger:: init ( ) ;
138
139
139
- if let Err ( err ) = app ( ) {
140
- eprintln ! ( "error: {}" , err ) ;
140
+ if let Err ( e ) = app ( ) {
141
+ error ! ( "{}" , e ) ;
141
142
std:: process:: exit ( 1 ) ;
142
143
}
143
144
}
0 commit comments