@@ -5,9 +5,9 @@ import { is_media_link_embed } from "../../../utils/discord.js";
55import { M } from "../../../utils/debugging-and-logging.js" ;
66import { MINUTE , SECOND } from "../../../common.js" ;
77import { BotComponent } from "../../../bot-component.js" ;
8- import { Wheatley } from "../../../wheatley.js" ;
98import { SelfClearingMap } from "../../../utils/containers.js" ;
109import { clear_timeout , set_timeout } from "../../../utils/node.js" ;
10+ import { channel_map } from "../../../channel-map.js" ;
1111
1212/* Here's a little of an explanation as to why we do this messageSnapshot stuff
1313 * A forwarded message is empty, however it contains a property messageSnapshot
@@ -40,8 +40,20 @@ function regular_has_media(message: Discord.Message | Discord.PartialMessage): b
4040const REACT_TIMEOUT = 90 * SECOND ;
4141
4242export default class Autoreact extends BotComponent {
43+ private channels = channel_map (
44+ this . wheatley ,
45+ this . wheatley . channels . introductions ,
46+ this . wheatley . channels . memes ,
47+ this . wheatley . channels . server_suggestions ,
48+ this . wheatley . channels . food ,
49+ ) ;
50+
4351 react_timeouts = new SelfClearingMap < string , NodeJS . Timeout > ( REACT_TIMEOUT ) ;
4452
53+ override async setup ( ) {
54+ await this . channels . resolve ( ) ;
55+ }
56+
4557 override async on_ready ( ) {
4658 await this . catch_up ( ) ;
4759 }
@@ -122,7 +134,7 @@ export default class Autoreact extends BotComponent {
122134 this . wheatley . warn ( "Unable to find emoji nog4g" ) ;
123135 }
124136 }
125- if ( message . channel . id == this . wheatley . channels . introductions . id ) {
137+ if ( message . channel . id == this . channels . introductions . id ) {
126138 if ( message . member == null ) {
127139 // TODO: Ping zelis?
128140 M . warn ( "Why??" , message ) ;
@@ -132,15 +144,15 @@ export default class Autoreact extends BotComponent {
132144 M . log ( "Waving to new user" , message . author . tag , message . author . id , message . url ) ;
133145 await message . react ( "👋" ) ;
134146 }
135- } else if ( message . channel . id == this . wheatley . channels . memes . id && has_media ( message ) ) {
147+ } else if ( message . channel . id == this . channels . memes . id && has_media ( message ) ) {
136148 M . log ( "Adding star reaction" , message . author . tag , message . author . id , message . url ) ;
137149 await message . react ( "⭐" ) ;
138- } else if ( message . channel . id == this . wheatley . channels . server_suggestions . id ) {
150+ } else if ( message . channel . id == this . channels . server_suggestions . id ) {
139151 M . log ( "Adding server suggestion reactions" , message . author . tag , message . author . id , message . url ) ;
140152 await message . react ( "👍" ) ;
141153 await message . react ( "👎" ) ;
142154 await message . react ( "🤷" ) ;
143- } else if ( message . channel . id == this . wheatley . channels . food . id && has_media ( message ) ) {
155+ } else if ( message . channel . id == this . channels . food . id && has_media ( message ) ) {
144156 const reaction = message . guild ! . emojis . cache . find ( emoji => emoji . name === "chefskiss" ) ;
145157 if ( reaction !== undefined ) {
146158 await message . react ( reaction ) ;
@@ -152,7 +164,7 @@ export default class Autoreact extends BotComponent {
152164 // reaction blocked
153165 if ( e instanceof Discord . DiscordAPIError && e . code === 90001 ) {
154166 await message . member ?. timeout ( 1 * MINUTE , "Thou shall not block the bot" ) ;
155- if ( message . channel . id == this . wheatley . channels . server_suggestions . id ) {
167+ if ( message . channel . id == this . channels . server_suggestions . id ) {
156168 await message . delete ( ) ;
157169 }
158170 } else {
@@ -177,7 +189,7 @@ export default class Autoreact extends BotComponent {
177189 if ( new_message . createdTimestamp && Date . now ( ) - new_message . createdTimestamp > 5 * MINUTE ) {
178190 return ;
179191 }
180- if ( new_message . channel . id == this . wheatley . channels . memes . id ) {
192+ if ( new_message . channel . id == this . channels . memes . id ) {
181193 const bot_starred = new_message . reactions . cache . get ( "⭐" ) ?. users . cache . has ( this . wheatley . user . id ) ;
182194 // If we haven't stared (or don't know if we've starred) and the new message has media, star
183195 if ( ! bot_starred && has_media ( new_message ) ) {
@@ -204,8 +216,7 @@ export default class Autoreact extends BotComponent {
204216 }
205217
206218 async catch_up ( ) {
207- const introductions_channel = await this . utilities . get_channel ( this . wheatley . channels . introductions ) ;
208- const messages = await introductions_channel . messages . fetch ( { limit : 100 , cache : false } ) ;
219+ const messages = await this . channels . introductions . messages . fetch ( { limit : 100 , cache : false } ) ;
209220 for ( const [ _ , message ] of messages ) {
210221 if ( await this . is_new_member ( message ) ) {
211222 M . log ( "Waving to new user" , message . author . tag , message . author . id , message . url ) ;
0 commit comments