-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6d2fcf4
Showing
5 changed files
with
887 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use strict"; | ||
import api from './api.js'; | ||
|
||
let config = { | ||
room: 'global', | ||
global: false, | ||
credentials: null, | ||
}; | ||
|
||
const id = a => a; | ||
|
||
const compose = ( f, g ) => { | ||
return x => { | ||
return f( g( x ) ); | ||
}; | ||
}; | ||
|
||
// maybe monad composition, basically | ||
const maybeCompose = ( f, g ) => { | ||
return x => { | ||
if( !f || !g ) return undefined; | ||
|
||
const y = g( x ); | ||
if( !y ) return undefined; | ||
else return f( x ); | ||
}; | ||
}; | ||
|
||
const handleMessages = ( self, ms ) => { | ||
const transform = self.transformers.reduce( (x, y) => maybeCompose(x, y), id ); | ||
const filter = self. filters.reduce( (x, y) => maybeCompose(x, y), id ); | ||
for( const m of ms ) { | ||
const mp = transform( m ); | ||
if( mp ) { | ||
if( filter( mp ) ) { | ||
self.consumer( mp ); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const reduceHtml = m => { | ||
const mp = m; | ||
// <p> | ||
//mp.message = m.message.substring( 3, m.message.length-5 ); | ||
|
||
// <a>gets left</a> | ||
mp.message = mp.message.replace( /<\/?a[\w ="':\/\\.]*>/gi, "" ); | ||
|
||
// <img> to :emotes: | ||
//mp.message = mp.message.replace( /<img[\w ="':\/\\.\-?]*>/gi, m => { | ||
// return m.search( /https:\/\/[\/\w\.\-?]*/ ); | ||
//}); | ||
return mp; | ||
}; | ||
|
||
const roomCheck = ( m ) => { | ||
return ( m.channel !== config.room && !config.global ) ? undefined : m; | ||
}; | ||
|
||
export default { | ||
|
||
get config() { return config; }, | ||
set config(c) { config = c; }, | ||
|
||
transformers: [ reduceHtml ], | ||
filters: [ roomCheck ], | ||
|
||
consumer( m ) { console.log( m ); }, | ||
|
||
async init() { | ||
api.rcvMessageBulk = ms => handleMessages( this, ms ); | ||
await api.init( this.config.room, this.config.credentials ); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default { | ||
prefix: '[bitwave.tv bot] ', | ||
|
||
info( message ) { | ||
console.log( this.prefix + message ); | ||
}, | ||
|
||
warn( message ) { | ||
console.warn( this.prefix + '[WARN] ' + message ); | ||
}, | ||
|
||
error( message ) { | ||
console.error( this.prefix + '[ERROR] ' + message ); | ||
}, | ||
}; |
Oops, something went wrong.