import _ from 'lodash' ; import { Preview , PreviewProvider , Previews , UnresolvedPreview } from 'libs/PreviewProvider' ; import StrawPoll from 'libs/StrawPoll' ; /**
 * RegExp used to identify a poll link.
 */ const PollRegExp = /https:\/\/(?:www\.)?strawpoll\.me\/(\d+)/g ; /**
 * Straw Poll preview provider.
 */ const PreviewStrawPoll = class { return public static getProviderId ( ) { return 'previewStrawPoll' ; } param message return public static parse ( message ) { const previews = { } ; let match ; while ( ( match = PollRegExp . exec ( message ) ) != null ) { previews [ match [ 1 ] ] = { id : match [ 1 ] , provider : PreviewStrawPoll . getProviderId ( ) , resolved : false } ; } return previews ; } param preview return public static async resolve ( preview ) { const poll = await StrawPoll . fetchPoll ( preview . id ) ; return { ... preview , icon : 'horizontal-bar-chart' , meta : `Total votes: ${ _ . sum ( poll . votes ) . toLocaleString ( ) } - Total options: ${ poll . options . length . toLocaleString ( ) }` , resolved : true , title : poll . title , url : `https://www.strawpoll.me/${ preview . id }` , } ; } } ; export default PreviewStrawPoll ;