@@ -20,16 +20,23 @@ use crate::db::DB;
20
20
use commands:: { Args , Commands } ;
21
21
use diesel:: prelude:: * ;
22
22
use serenity:: { model:: prelude:: * , prelude:: * } ;
23
+ use serde:: Deserialize ;
24
+ use envy;
23
25
24
26
pub ( crate ) type Result = crate :: commands:: Result < ( ) > ;
25
27
26
- fn init_data ( ) -> Result {
28
+ #[ derive( Deserialize ) ]
29
+ struct Config {
30
+ tags : bool ,
31
+ crates : bool ,
32
+ }
33
+
34
+ fn init_data ( config : & Config ) -> Result {
27
35
use crate :: schema:: roles;
28
36
info ! ( "Loading data into database" ) ;
37
+
29
38
let mod_role = std:: env:: var ( "MOD_ID" ) . map_err ( |_| "MOD_ID env var not found" ) ?;
30
39
let talk_role = std:: env:: var ( "TALK_ID" ) . map_err ( |_| "TALK_ID env var not found" ) ?;
31
- let wg_and_teams_role =
32
- std:: env:: var ( "WG_AND_TEAMS_ID" ) . map_err ( |_| "WG_AND_TEAMS_ID env var not found" ) ?;
33
40
34
41
let conn = DB . get ( ) ?;
35
42
@@ -50,7 +57,9 @@ fn init_data() -> Result {
50
57
. run :: < _ , Box < dyn std:: error:: Error > , _ > ( || {
51
58
upsert_role ( "mod" , & mod_role) ?;
52
59
upsert_role ( "talk" , & talk_role) ?;
53
- upsert_role ( "wg_and_teams" , & wg_and_teams_role) ?;
60
+ if config. tags || config. crates {
61
+ upsert_role ( "wg_and_teams" , & std:: env:: var ( "WG_AND_TEAMS_ID" ) . map_err ( |_| "WG_AND_TEAMS_ID env var not found" ) ?) ?;
62
+ }
54
63
55
64
Ok ( ( ) )
56
65
} ) ?;
@@ -60,29 +69,36 @@ fn init_data() -> Result {
60
69
61
70
fn app ( ) -> Result {
62
71
info ! ( "starting..." ) ;
72
+
73
+ let config = envy:: from_env :: < Config > ( ) ?;
74
+
63
75
let token = std:: env:: var ( "DISCORD_TOKEN" )
64
76
. map_err ( |_| "missing environment variable: DISCORD_TOKEN" ) ?;
65
77
66
78
let _ = db:: run_migrations ( ) ?;
67
79
68
- let _ = init_data ( ) ?;
80
+ let _ = init_data ( & config ) ?;
69
81
70
82
let mut cmds = Commands :: new ( ) ;
71
83
72
- // Tags
73
- cmds. add ( "?tags delete {key}" , tags:: delete) ;
74
- cmds. add ( "?tags create {key} value..." , tags:: post) ;
75
- cmds. add ( "?tags help" , tags:: help) ;
76
- cmds. add ( "?tags" , tags:: get_all) ;
77
- cmds. add ( "?tag {key}" , tags:: get) ;
84
+ if config. tags {
85
+ // Tags
86
+ cmds. add ( "?tags delete {key}" , tags:: delete) ;
87
+ cmds. add ( "?tags create {key} value..." , tags:: post) ;
88
+ cmds. add ( "?tags help" , tags:: help) ;
89
+ cmds. add ( "?tags" , tags:: get_all) ;
90
+ cmds. add ( "?tag {key}" , tags:: get) ;
91
+ }
78
92
79
- // crates.io
80
- cmds. add ( "?crate help" , crates:: help) ;
81
- cmds. add ( "?crate query..." , crates:: search) ;
93
+ if config. crates {
94
+ // crates.io
95
+ cmds. add ( "?crate help" , crates:: help) ;
96
+ cmds. add ( "?crate query..." , crates:: search) ;
82
97
83
- // docs.rs
84
- cmds. add ( "?docs help" , crates:: doc_help) ;
85
- cmds. add ( "?docs query..." , crates:: doc_search) ;
98
+ // docs.rs
99
+ cmds. add ( "?docs help" , crates:: doc_help) ;
100
+ cmds. add ( "?docs query..." , crates:: doc_search) ;
101
+ }
86
102
87
103
// Slow mode.
88
104
// 0 seconds disables slowmode
0 commit comments