File tree 3 files changed +35
-29
lines changed
3 files changed +35
-29
lines changed Original file line number Diff line number Diff line change 1
1
import fs from 'fs' ;
2
- import utf from 'utf-8 ' ;
2
+ import dotenv from 'dotenv ' ;
3
3
import Snoowrap from 'snoowrap' ;
4
4
import snoostorm from 'snoostorm' ;
5
- import dotenv from 'dotenv ' ;
5
+ import decode from './util/decode.mjs ' ;
6
6
7
7
// Awaiting top level await 😭
8
8
let ignoredUsers ;
@@ -33,30 +33,3 @@ comments.on('item', (comment) => {
33
33
comment . reply ( `That translates to: "${ translated } ". ${ botNotice } ` ) ;
34
34
}
35
35
} ) ;
36
-
37
- function decode ( string ) {
38
- const delimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
39
- const nonDelimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
40
- const byteRegex = / [ 0 1 ] { 8 } / gm;
41
-
42
- string = string . trim ( ) ;
43
-
44
- if ( delimited . test ( `${ string } ` ) || nonDelimited . test ( string ) ) {
45
- const bytes = string . replace ( / / g, '' ) . match ( byteRegex ) ;
46
- return decodeBytes ( bytes ) ;
47
- }
48
-
49
- return '' ;
50
- }
51
-
52
- function decodeBytes ( bytes ) {
53
- let decoded ;
54
-
55
- try {
56
- decoded = utf . getStringFromBytes ( bytes . map ( byte => parseInt ( byte , 2 ) ) ) ;
57
- } catch ( error ) {
58
- decoded = '' ;
59
- }
60
-
61
- return decoded ;
62
- }
Original file line number Diff line number Diff line change
1
+ import utf from 'utf-8' ;
2
+
3
+ function decodeBytes ( bytes ) {
4
+ let decoded ;
5
+
6
+ try {
7
+ decoded = utf . getStringFromBytes ( bytes . map ( byte => parseInt ( byte , 2 ) ) ) ;
8
+ } catch ( error ) {
9
+ decoded = '' ;
10
+ }
11
+
12
+ return decoded ;
13
+ }
14
+
15
+ export default decodeBytes ;
Original file line number Diff line number Diff line change
1
+ import decodeBytes from './decode-bytes.mjs' ;
2
+
3
+ function decode ( string ) {
4
+ const delimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
5
+ const nonDelimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
6
+ const byteRegex = / [ 0 1 ] { 8 } / gm;
7
+
8
+ string = string . trim ( ) ;
9
+
10
+ if ( delimited . test ( `${ string } ` ) || nonDelimited . test ( string ) ) {
11
+ const bytes = string . replace ( / / g, '' ) . match ( byteRegex ) ;
12
+ return decodeBytes ( bytes ) ;
13
+ }
14
+
15
+ return '' ;
16
+ }
17
+
18
+ export default decode ;
You can’t perform that action at this time.
0 commit comments