@@ -7,10 +7,11 @@ import chalk from 'chalk';
7
7
import 'dotenv/config' ;
8
8
import { start } from 'repl' ;
9
9
10
- let { markAsBot, timeCheckInterval, responseMessage, invalidMessage, showLogs, overflowMessage, finalMessage } = load ( readFileSync ( 'config.yaml' , 'utf8' ) ) ;
10
+ let { markAsBot, timeCheckInterval, responseMessage, invalidMessage, showLogs, overflowMessage, finalMessage, allowKeywords } = load ( readFileSync ( 'config.yaml' , 'utf8' ) ) ;
11
11
12
12
markAsBot = markAsBot ?? true ;
13
13
showLogs = showLogs ?? false ;
14
+ allowKeywords = allowKeywords ?? false ; // DO NOT ENABLE
14
15
15
16
log ( `${ chalk . magenta ( 'STARTED:' ) } Started Bot` )
16
17
@@ -46,24 +47,77 @@ const db = new sqlite3.Database('remindme.sqlite3', (err) => {
46
47
// -----------------------------------------------------------------------------
47
48
// Main Bot Code
48
49
50
+ let handlers = { }
49
51
50
- const bot = new LemmyBot . LemmyBot ( {
51
- instance : process . env . LEMMY_INSTANCE ,
52
- credentials : {
53
- username : process . env . LEMMY_USERNAME ,
54
- password : process . env . LEMMY_PASSWORD ,
55
- } ,
56
- dbFile : 'db.sqlite3' ,
57
- federation : 'all' ,
58
- markAsBot : markAsBot ,
59
- handlers : {
60
- mention : async ( {
61
- mentionView : { comment } ,
52
+ handlers [ "mention" ] = async ( {
53
+ mentionView : { comment } ,
54
+ botActions : { createComment } ,
55
+ } ) => {
56
+ const words = comment . content . split ( ' ' ) ;
57
+ let amount = 0 ;
58
+
59
+ for ( let i = 1 ; i < words . length ; i ++ ) {
60
+ const word = words [ i ] ;
61
+
62
+ if ( word === 'seconds' || word === 'second' ) {
63
+ const seconds = parseInt ( words [ i - 1 ] ) ;
64
+ if ( seconds ) amount += seconds ;
65
+ }
66
+ else if ( word === 'minutes' || word === 'minute' ) {
67
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 ;
68
+ if ( seconds ) amount += seconds ;
69
+ }
70
+ else if ( word === 'hours' || word === 'hour' ) {
71
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 ;
72
+ if ( seconds ) amount += seconds ;
73
+ }
74
+ else if ( word === 'days' || word === 'day' ) {
75
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 ;
76
+ if ( seconds ) amount += seconds ;
77
+ }
78
+ else if ( word === 'weeks' || word === 'week' ) {
79
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 ;
80
+ if ( seconds ) amount += seconds ;
81
+ }
82
+ else if ( word === 'months' || word === 'month' ) {
83
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 * 4 ;
84
+ if ( seconds ) amount += seconds ;
85
+ }
86
+ else if ( word === 'years' || word === 'year' ) {
87
+ const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 * 4 * 12 ;
88
+ if ( seconds ) amount += seconds ;
89
+ }
90
+ }
91
+
92
+ if ( amount > 0 ) {
93
+ // Stop larger than 10 years
94
+ if ( amount > 315360000 ) {
95
+ createComment ( { content : overflowMessage , parent_id : comment . id , post_id : comment . post_id } ) ;
96
+ return ;
97
+ }
98
+
99
+ addReminder ( amount , comment . ap_id , createComment , comment ) ;
100
+ }
101
+ else {
102
+ createComment ( { content : invalidMessage , parent_id : comment . id , post_id : comment . post_id } ) ;
103
+ }
104
+ }
105
+
106
+ if ( allowKeywords ) {
107
+ handlers [ "comment" ] = {
108
+ sort : 'New' ,
109
+ handle : async ( {
110
+ commentView : {
111
+ comment,
112
+ } ,
62
113
botActions : { createComment } ,
63
114
} ) => {
64
115
const words = comment . content . split ( ' ' ) ;
65
116
let amount = 0 ;
66
117
118
+ if ( words . length < 1 ) return ;
119
+ if ( words [ 0 ] . toLowerCase ( ) !== '!remindme' && words [ 0 ] . toLowerCase ( ) !== '@remindme' ) return ;
120
+
67
121
for ( let i = 1 ; i < words . length ; i ++ ) {
68
122
const word = words [ i ] ;
69
123
@@ -109,70 +163,21 @@ const bot = new LemmyBot.LemmyBot({
109
163
else {
110
164
createComment ( { content : invalidMessage , parent_id : comment . id , post_id : comment . post_id } ) ;
111
165
}
112
- } ,
113
- comment : {
114
- sort : 'New' ,
115
- handle : async ( {
116
- commentView : {
117
- comment,
118
- } ,
119
- botActions : { createComment } ,
120
- } ) => {
121
- const words = comment . content . split ( ' ' ) ;
122
- let amount = 0 ;
123
-
124
- if ( words . length < 1 ) return ;
125
- if ( words [ 0 ] . toLowerCase ( ) !== '!remindme' && words [ 0 ] . toLowerCase ( ) !== '@remindme' ) return ;
126
-
127
- for ( let i = 1 ; i < words . length ; i ++ ) {
128
- const word = words [ i ] ;
129
-
130
- if ( word === 'seconds' || word === 'second' ) {
131
- const seconds = parseInt ( words [ i - 1 ] ) ;
132
- if ( seconds ) amount += seconds ;
133
- }
134
- else if ( word === 'minutes' || word === 'minute' ) {
135
- const seconds = parseInt ( words [ i - 1 ] ) * 60 ;
136
- if ( seconds ) amount += seconds ;
137
- }
138
- else if ( word === 'hours' || word === 'hour' ) {
139
- const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 ;
140
- if ( seconds ) amount += seconds ;
141
- }
142
- else if ( word === 'days' || word === 'day' ) {
143
- const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 ;
144
- if ( seconds ) amount += seconds ;
145
- }
146
- else if ( word === 'weeks' || word === 'week' ) {
147
- const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 ;
148
- if ( seconds ) amount += seconds ;
149
- }
150
- else if ( word === 'months' || word === 'month' ) {
151
- const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 * 4 ;
152
- if ( seconds ) amount += seconds ;
153
- }
154
- else if ( word === 'years' || word === 'year' ) {
155
- const seconds = parseInt ( words [ i - 1 ] ) * 60 * 60 * 24 * 7 * 4 * 12 ;
156
- if ( seconds ) amount += seconds ;
157
- }
158
- }
159
-
160
- if ( amount > 0 ) {
161
- // Stop larger than 10 years
162
- if ( amount > 315360000 ) {
163
- createComment ( { content : overflowMessage , parent_id : comment . id , post_id : comment . post_id } ) ;
164
- return ;
165
- }
166
+ }
167
+ }
168
+ }
166
169
167
- addReminder ( amount , comment . ap_id , createComment , comment ) ;
168
- }
169
- else {
170
- createComment ( { content : invalidMessage , parent_id : comment . id , post_id : comment . post_id } ) ;
171
- }
172
- }
173
- } ,
174
170
171
+ const bot = new LemmyBot . LemmyBot ( {
172
+ instance : process . env . LEMMY_INSTANCE ,
173
+ credentials : {
174
+ username : process . env . LEMMY_USERNAME ,
175
+ password : process . env . LEMMY_PASSWORD ,
175
176
} ,
177
+ dbFile : 'db.sqlite3' ,
178
+ federation : 'all' ,
179
+ markAsBot : markAsBot ,
180
+ handlers : handlers ,
176
181
schedule : [
177
182
{
178
183
cronExpression : `0 */${ timeCheckInterval } * * * *` ,
0 commit comments