File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Message } from "../../types/message" ;
2+ import { phishingSet } from ".." ;
3+ import { normalize } from "../components/utils/url" ;
4+ import log from "../components/utils/log" ;
5+
6+ export const info = {
7+ command : "phishing" ,
8+ description : "A simple phishtank test command." ,
9+ usage : "phishing" ,
10+ example : "phishing" ,
11+ role : "user" ,
12+ cooldown : 5000 ,
13+ } ;
14+
15+ export default async function ( msg : Message ) {
16+ if ( ! / ^ p h i s h i n g / i. test ( msg . body ) ) return ;
17+
18+ if ( ! msg . hasQuotedMsg ) {
19+ const testMessage = `
20+ \`Phishtank\`
21+
22+ Found ${ phishingSet . size } phishing pages.
23+ Hint: You can reply this command to messages.
24+ ` ;
25+
26+ await msg . reply ( testMessage ) ;
27+ return ;
28+ }
29+
30+ const qouted = await msg . getQuotedMessage ( ) ;
31+ const extractUrls = qouted . body . match ( / ( h t t p s ? : \/ \/ [ ^ \s ] + ) / g) || [ ] ;
32+ const urls = extractUrls
33+ . map ( ( url ) => normalize ( url ) )
34+ . filter ( ( u ) : u is string => Boolean ( u ) ) ;
35+ const spamUrls = urls . filter ( ( url ) => phishingSet . has ( url ) ) ;
36+ if ( spamUrls . length == 0 ) {
37+ const testMessage = `
38+ \`Phishtank\`
39+
40+ This message doesn't contain any links or so.
41+ ` ;
42+
43+ await msg . reply ( testMessage ) ;
44+ return ;
45+ }
46+
47+ const text = `
48+ \`Phishing Alert\`
49+
50+ We've found that this url(s): \`${ spamUrls . join ( ", " ) } \`
51+ to be phishing site/page.
52+ Proceed with caution.
53+ ` ;
54+ await msg . reply ( text ) ;
55+ }
Original file line number Diff line number Diff line change @@ -46,18 +46,20 @@ export default async function (msg: Message, type: string) {
4646
4747 const lid = msg . author ? msg . author . split ( "@" ) [ 0 ] : msg . from . split ( "@" ) [ 0 ] ;
4848
49- // process normalization
50- msg . body = msg . body
51- . normalize ( "NFKC" )
52- . replace ( / [ \u0300 - \u036f \u00b4 \u0060 \u005e \u007e ] / g, "" )
53- . trim ( ) ;
54-
5549 /*
5650 * Block users from running commands.
5751 */
5852 const isBlockedUser = await isBlocked ( lid ) ;
5953 if ( isBlockedUser ) return ;
6054
55+ const prefix = ! msg . body . startsWith ( commandPrefix ) ;
56+
57+ /*
58+ * Prefix
59+ */
60+ if ( ! commandPrefixLess && prefix ) return ;
61+ if ( msg . fromMe && prefix ) return ;
62+
6163 /*
6264 *
6365 * Check for scam urls
@@ -84,6 +86,12 @@ export default async function (msg: Message, type: string) {
8486
8587 if ( msg . isForwarded ) return ;
8688
89+ // process normalization
90+ msg . body = msg . body
91+ . normalize ( "NFKC" )
92+ . replace ( / [ \u0300 - \u036f \u00b4 \u0060 \u005e \u007e ] / g, "" )
93+ . trim ( ) ;
94+
8795 /*
8896 *
8997 * Quiz command validation
@@ -95,14 +103,6 @@ export default async function (msg: Message, type: string) {
95103 } ) ;
96104 }
97105
98- const prefix = ! msg . body . startsWith ( commandPrefix ) ;
99-
100- /*
101- * Prefix
102- */
103- if ( ! commandPrefixLess && prefix ) return ;
104- if ( msg . fromMe && prefix ) return ;
105-
106106 /*
107107 *
108108 * Override the default function
Original file line number Diff line number Diff line change @@ -43,10 +43,11 @@ export async function findOrCreateUser(msg: Message): Promise<boolean> {
4343 commandCount : 1 ,
4444 } ,
4545 } ) ;
46+ return true ;
4647 } catch ( error ) {
4748 log . error ( "Database" , `Failed to find or create user.` , error ) ;
4849 }
49- return true ;
50+ return false ;
5051}
5152
5253export async function getUserbyLid ( lid : string ) {
Original file line number Diff line number Diff line change @@ -18,13 +18,14 @@ const monitor = new MemoryMonitor({
1818 thresholdMB : parseInt ( process . env . PROJECT_THRESHOLD_MEMORY || "1024" , 10 ) ,
1919} ) ;
2020const phishtank = new PhishTankClient ( ) ;
21- const phishingSet : Set < string > = phishtank . getPhishingSet ( ) ;
21+ let phishingSet : Set < string > ;
2222
2323async function main ( ) {
2424 checkRequirements ( ) ;
2525 monitor . start ( ) ;
2626 phishtank . startAutoUpdateLoop ( ) ;
2727 await phishtank . init ( ) ;
28+ phishingSet = phishtank . getPhishingSet ( ) ;
2829 await client . initialize ( ) ;
2930
3031 mapCommands ( ) ;
You can’t perform that action at this time.
0 commit comments