@@ -6,12 +6,10 @@ mod util;
6
6
use std:: collections:: { HashSet } ;
7
7
use commands:: { get_framework} ;
8
8
use models:: config:: Config ;
9
- use services:: { * , database:: Database } ;
10
9
use std:: fs;
11
10
use std:: sync:: Arc ;
12
11
use std:: env;
13
12
use env_logger:: Env ;
14
- use lavalink_rs:: { LavalinkClient , gateway:: LavalinkEventHandler } ;
15
13
use serenity:: {
16
14
async_trait,
17
15
client:: { Client , Context , EventHandler , bridge:: gateway:: GatewayIntents } ,
@@ -21,54 +19,6 @@ use serenity::{
21
19
prelude:: TypeMapKey
22
20
} ;
23
21
use log:: { error, info} ;
24
- use songbird:: SerenityInit ;
25
-
26
- struct Handler {
27
- framework : Arc < Box < dyn Framework + Sync + std:: marker:: Send > > ,
28
- database : Arc < Database >
29
- }
30
-
31
- struct Lavalink ;
32
-
33
- impl TypeMapKey for Lavalink {
34
- type Value = LavalinkClient ;
35
- }
36
-
37
- struct LavalinkHandler ;
38
-
39
- #[ async_trait]
40
- impl LavalinkEventHandler for LavalinkHandler { }
41
-
42
- #[ async_trait]
43
- impl EventHandler for Handler {
44
- async fn guild_member_addition ( & self , ctx : Context , guild_id : GuildId , new_member : Member ) {
45
- message_handler:: on_join ( & ctx, & guild_id, & new_member) . await ;
46
- }
47
-
48
- async fn message ( & self , ctx : Context , msg : Message ) {
49
- message_handler:: message ( & ctx, & msg) . await ;
50
- }
51
-
52
- async fn reaction_add ( & self , ctx : Context , added_reaction : Reaction ) {
53
- crate :: commands:: cowboard:: cowboard_handler:: add_reaction ( & ctx, & added_reaction) . await ;
54
- }
55
-
56
- async fn reaction_remove ( & self , ctx : Context , removed_reaction : Reaction ) {
57
- crate :: commands:: cowboard:: cowboard_handler:: remove_reaction ( & ctx, & removed_reaction) . await ;
58
- }
59
-
60
- async fn reaction_remove_all ( & self , ctx : Context , channel_id : ChannelId , removed_from_message_id : MessageId ) {
61
- crate :: commands:: cowboard:: cowboard_handler:: reaction_remove_all ( & ctx, channel_id, removed_from_message_id) . await ;
62
- }
63
-
64
- async fn ready ( & self , ctx : Context , ready : Ready ) {
65
- bot_init:: ready ( & ctx, & ready) . await ;
66
- }
67
-
68
- async fn interaction_create ( & self , ctx : Context , interaction : Interaction ) {
69
- interaction_handler:: interaction ( & ctx, & interaction, & self . framework ) . await ;
70
- }
71
- }
72
22
73
23
async fn init_logger ( ) -> std:: io:: Result < ( ) > {
74
24
let env = Env :: default ( ) . default_filter_or ( "warning" ) ;
@@ -117,55 +67,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
117
67
let token = config. token ;
118
68
let ( app_id, owners) = fetch_bot_info ( & token) . await ;
119
69
let framework = get_framework ( & config. cmd_prefix , app_id, owners) . await ;
120
-
121
- let event_handler = Handler {
122
- framework : framework. clone ( ) ,
123
- database : Arc :: new ( Database :: new ( & * config. sql_server_ip , config. sql_server_port , & * config. sql_server_username , & * config. sql_server_password ) . await . unwrap ( ) )
124
- } ;
125
-
126
70
let db_clone = event_handler. database . clone ( ) ;
127
71
128
72
let mut client = Client :: builder ( & token)
129
73
. event_handler ( event_handler)
130
74
. application_id ( * app_id. as_u64 ( ) )
131
75
. framework_arc ( framework)
132
76
. intents ( GatewayIntents :: all ( ) )
133
- . register_songbird ( )
134
77
. await
135
78
. expect ( "Discord failed to initialize" ) ;
136
79
137
- let lavalink_enabled = !config. lavalink_ip . is_empty ( ) && !config. lavalink_password . is_empty ( ) ;
138
-
139
- if lavalink_enabled {
140
- match LavalinkClient :: builder ( * app_id. as_u64 ( ) )
141
- . set_host ( config. lavalink_ip )
142
- . set_password (
143
- config. lavalink_password ,
144
- )
145
- . build ( LavalinkHandler )
146
- . await {
147
- Ok ( lava_client) => {
148
- let mut data = client. data . write ( ) . await ;
149
- data. insert :: < Lavalink > ( lava_client) ;
150
- }
151
- Err ( ex) => {
152
- error ! ( "Failed to initialize LavaLink. {}" , ex) ;
153
- }
154
- }
155
- }
156
-
157
- {
158
- let mut data = client. data . write ( ) . await ;
159
- // Should I wrap it with an RwLock? ...it's pooled and async is nice, but...
160
- data. insert :: < Database > ( db_clone) ;
161
- }
162
-
163
- // Start our reminder task and forget about it.
164
- let _ = tokio:: task:: spawn ( crate :: commands:: ucm:: reminders:: check_reminders ( client. data . clone ( ) , client. cache_and_http . clone ( ) ) ) ;
165
-
166
80
if let Err ( ex) = client. start ( ) . await {
167
81
error ! ( "Discord bot client error: {:?}" , ex) ;
168
82
}
169
83
170
84
Ok ( ( ) )
171
- }
85
+ }
0 commit comments