1
- use crate :: cache:: Cache ;
2
1
use crate :: websocket_server:: DiscordToClanChatMessage ;
3
2
use crate :: { handler, ChatServerHandle } ;
4
3
use actix_web:: web:: Data ;
@@ -13,12 +12,12 @@ use tokio::task::spawn_local;
13
12
use trackscape_discord_shared:: database:: BotMongoDb ;
14
13
use trackscape_discord_shared:: ge_api:: ge_api:: get_item_mapping;
15
14
use trackscape_discord_shared:: helpers:: hash_string;
16
- use trackscape_discord_shared:: jobs:: job_helpers:: get_redis_client;
17
15
use trackscape_discord_shared:: jobs:: CeleryJobQueue ;
18
16
use trackscape_discord_shared:: osrs_broadcast_extractor:: osrs_broadcast_extractor:: {
19
17
get_wiki_clan_rank_image_url, ClanMessage ,
20
18
} ;
21
19
use trackscape_discord_shared:: osrs_broadcast_handler:: OSRSBroadcastHandler ;
20
+ use trackscape_discord_shared:: redis_helpers:: { fetch_redis, write_to_cache_with_seconds} ;
22
21
use trackscape_discord_shared:: wiki_api:: wiki_api:: get_quests_and_difficulties;
23
22
use web:: Json ;
24
23
@@ -79,7 +78,7 @@ async fn new_discord_message(
79
78
async fn new_clan_chats (
80
79
req : HttpRequest ,
81
80
discord_http_client : Data < Http > ,
82
- cache : Data < Cache > ,
81
+ redis_client : Data < redis :: Client > ,
83
82
new_chat : Json < Vec < ClanMessage > > ,
84
83
mongodb : Data < BotMongoDb > ,
85
84
celery : Data < Arc < Celery > > ,
@@ -127,12 +126,18 @@ async fn new_clan_chats(
127
126
//Checks to make sure the message has not already been process since multiple people could be submitting them
128
127
let message_content_hash =
129
128
hash_string ( format ! ( "{}{}" , chat. message. clone( ) , chat. sender. clone( ) ) ) ;
130
- match cache. get_value ( message_content_hash. clone ( ) ) . await {
131
- Some ( _) => continue ,
132
- None => {
133
- cache
134
- . set_value ( message_content_hash. clone ( ) , "true" . to_string ( ) )
135
- . await ;
129
+
130
+ let mut redis_connection = redis_client
131
+ . get_connection ( )
132
+ . expect ( "Could not connect to redis" ) ;
133
+
134
+ let redis_key = format ! ( "MessageHashes:{}" , message_content_hash) ;
135
+ match fetch_redis :: < String > ( & mut redis_connection, & redis_key) . await {
136
+ Ok ( _) => {
137
+ continue ;
138
+ }
139
+ Err ( _) => {
140
+ write_to_cache_with_seconds ( & mut redis_connection, & redis_key, true , 10 ) . await
136
141
}
137
142
}
138
143
@@ -143,6 +148,7 @@ async fn new_clan_chats(
143
148
}
144
149
145
150
if registered_guild. clan_name . clone ( ) . unwrap ( ) != chat. clan_name {
151
+ error ! ( "Clan name does not match the clan name saved in the database" ) ;
146
152
continue ;
147
153
}
148
154
@@ -213,9 +219,6 @@ async fn new_clan_chats(
213
219
214
220
let league_world = chat. is_league_world . unwrap_or ( false ) ;
215
221
216
- // TODO: Load this from Redis
217
- let mut redis_connection = get_redis_client ( ) . unwrap ( ) ;
218
-
219
222
let item_mapping_from_redis = get_item_mapping ( & mut redis_connection) . await ;
220
223
221
224
let quests_from_redis = get_quests_and_difficulties ( & mut redis_connection) . await ;
0 commit comments