UNPKG

tweeter-client

Version:
6 lines 25.3 kB
#!/usr/bin/env node /*! *** Tweeter Client 4.8.0 *** Copyright © 2020, Jaid <jaid.jsx@gmail.com> (https://github.com/Jaid) *** @license MIT !*/!function(t){var e={};function i(s){if(e[s])return e[s].exports;var n=e[s]={i:s,l:!1,exports:{}};return t[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(s,n,function(e){return t[e]}.bind(null,n));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=26)}([function(t,e){t.exports=require("@hapi/joi")},function(t,e,i){"use strict";i.d(e,"c",(function(){return h})),i.d(e,"a",(function(){return l}));var s=i(5),n=i.n(s),r=i(12),a=i.n(r);const o=new n.a({name:"Tweeter Client",version:"4.8.0",gotLogLevel:"info",useGot:!0,configSetup:{defaults:a(),secretKeys:["apiKey"]}}),h=o.logger,l=o.config;e.b=o},function(t,e){t.exports=require("has-content")},function(t,e){t.exports=require("jimp")},function(t,e){t.exports=require("regex-parser")},function(t,e){t.exports=require("jaid-core")},function(t,e){t.exports=require("ensure-array")},function(t,e){t.exports=require("got")},function(t,e){t.exports=require("handlebars")},function(t,e){t.exports=require("@absolunet/fsp")},function(t,e){t.exports=require("canvas")},function(t,e){t.exports=require("yargs")},function(t,e){t.exports={apiHost:"localhost",apiProtocol:"http",apiPort:80,tweeters:[],apiUser:"jaid"}},function(t,e){t.exports=require("jsqr")},function(t,e){t.exports=require("remove-accents")},function(t,e){t.exports=require("ensure-object")},function(t,e){t.exports=require("flatten-multiline")},function(t,e){t.exports=require("twit")},function(t,e){t.exports=require("dead-by-daylight")},function(t,e){t.exports=require("humanize-list")},function(t,e){t.exports=require("node-schedule")},function(t,e){t.exports=require("pick-random")},function(t,e){t.exports=require("render-dead-by-daylight-build")},function(t,e){t.exports=require("qrcode")},function(t,e){t.exports=require("moment")},function(t,e){t.exports=require("steam-game-update-watcher")},function(t,e,i){"use strict";i.r(e);var s=i(11),n=i.n(s),r=i(1);function a(t){var e;(null===r.b||void 0===r.b||null===(e=r.b.logger)||void 0===e?void 0:e.error)?r.b.logger.error(t):console.error(t)}process.on("unhandledRejection",t=>{a(t?`Unhandled promise rejection: ${(null==t?void 0:t.message)||t}`:"Unhandled promise rejection"),(null==t?void 0:t.stack)&&a(t.stack)}),n.a.scriptName("tweeter-client").version("4.8.0").command("$0","Creates tweets.",{},(function(){(async function(){const t={},e=i(27);for(const i of e.keys()){const{pluginName:s}=i.match(/[/\\](?<pluginName>.+?)[/\\]index\.js$/).groups;t[s]=e(i).default}await r.b.init(t)})().catch(t=>{a("Core process crashed"),a(t),process.exit(1)})})).argv},function(t,e,i){var s={"./main/index.js":28};function n(t){var e=r(t);return i(e)}function r(t){if(!i.o(s,t)){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}return s[t]}n.keys=function(){return Object.keys(s)},n.resolve=r,t.exports=n,n.id=27},function(t,e,i){"use strict";i.r(e);var s=i(6),n=i.n(s),r=i(2),a=i.n(r),o=i(5),h=i(1);let l=1;class c{constructor(t,e,i,s){this.handle=t,this.dry=e,this.logger=i,this.index=l,this.options=s,l++;for(const[t,e]of Object.entries(this.options))this.logger.debug(`${t}: ${JSON.stringify(e)}`)}static initStatic(){const t=dt.core.got;c.apiGot=t.extend({method:"POST",prefixUrl:`${h.a.apiProtocol}://${h.a.apiHost}`,port:h.a.apiPort,hooks:{init:[t=>{t.json||(t.json={}),Object.assign(t.json,{apiUser:h.a.apiUser,apiKey:h.a.apiKey})}]}})}async post(t,e){try{if(this.logger.info("[Tweeter #%s] @%s: %s",this.index,this.handle,t),e&&this.logger.debug(`Media length: ${e.length}`),this.dry)return;const i=await c.apiGot.post("tweet",{json:{text:t,media:e,handle:this.handle}});this.logger.debug("Tweet result: [%s %s] %s",i.statusCode,i.statusMessage,i.body)}catch(t){this.logger.error("[Tweeter #%s] Could not send tweet: %s",this.index,t)}}async postMedia(t){await this.post("",t)}}c.apiGot=null;var u=i(0),d=i.n(u),p=i(7),f=i.n(p);function g(t,e=0,i=9e3){var s=Math.min;let n=BigInt("144066263297769815596495629667062367629");const r=BigInt("309485009821345068724781371");if("string"==typeof t){const a=s(e+i,t.length);for(let i=e;a>i;i++)n^=BigInt(t.charCodeAt(i)),n=BigInt.asUintN(128,n*r)}else if(t instanceof Uint8Array){const a=s(e+i,t.byteLength);for(let i=e;a>i;i++)n^=BigInt(t[i]),n=BigInt.asUintN(128,n*r)}else if(t instanceof ArrayBuffer){const a=new Uint8Array(t),o=s(e+i,a.byteLength);for(let t=e;o>t;t++)n^=BigInt(a[t]),n=BigInt.asUintN(128,n*r)}return`0000000000000000000000000000000${n.toString(16)}`.slice(-32)}class y{constructor(t=null){if(this.b=null,t instanceof ArrayBuffer){this.b=new ArrayBuffer(t.byteLength>620?2160:620),this.dataView=new DataView(this.b,0,this.b.byteLength),this.dataBytes=new Uint8Array(this.b,0,this.b.byteLength);const e=new Uint8Array(t,0,t.byteLength);for(let i=0;i<t.byteLength&&i<this.b.byteLength;++i)this.dataBytes[i]=e[i]}if(t instanceof Uint8Array){this.b=new ArrayBuffer(t.byteLength>620?2160:620),this.dataView=new DataView(this.b,0,this.b.byteLength),this.dataBytes=new Uint8Array(this.b,0,this.b.byteLength);for(let e=0;e<t.byteLength&&e<this.b.byteLength;++e)this.dataBytes[e]=t[e]}if("string"==typeof t&&t.length>=620){this.b=new ArrayBuffer(t.length>620?2160:620),this.dataView=new DataView(this.b,0,this.b.byteLength),this.dataBytes=new Uint8Array(this.b,0,this.b.byteLength);for(let e=0;e<t.length&&e<this.b.byteLength;++e)this.dataBytes[e]=t.charCodeAt(e)}if(null===this.b){let e=9;"number"==typeof t&&(e=t),this.b=new ArrayBuffer(y.bytesForType(e)),this.dataView=new DataView(this.b,0,this.b.byteLength),this.dataBytes=new Uint8Array(this.b,0,this.b.byteLength),this.title="Empty",this.creator=["Unknown",0],this.town=["Unknown",0],this.unknown_a=12569,this.setDefaultPalette(),this.unknown_b=204,this.unknown_c=10,this.patternType=e}this.currMask=y.typeInfo[this.patternType]?y.typeInfo[this.patternType].mask:null}utf16_decode(t,e){let i="";for(let s=0;e>s;s+=2){const e=this.dataView.getUint16(t+s,!0);if(0===e)return i;i+=String.fromCharCode(e)}return i}utf16_encode(t,e,i){for(let s=0;e/2>s;s++)s<i.length?this.dataView.setUint16(t+2*s,i.charCodeAt(s),!0):this.dataView.setUint16(t+2*s,0,!0)}toString(){let t="";const e=Math.min(this.byteLength,this.b.byteLength);for(let i=0;e>i;i++)t+=String.fromCharCode(this.dataBytes[i]);return t}toJson(){return{title:this.title,author:this.creator,authorTitle:this.creator[0]?this.creator[0]:null,town:this.town,townTitle:this.town[0]?this.town[0]:null,unknown:{a:this.unknown_a,b:this.unknown_b,c:this.unknown_c,d:this.unknown_d},textureSize:this.width,patternType:this.patternType,patternTypeTitle:y.getTypeStr(this.patternType),byteLength:this.byteLength}}toPixels(t){let e=0;for(let i=108;i<this.b.byteLength&&e<t.byteLength;i++)t[e++]=15&this.dataBytes[i],t[e++]=15&this.dataBytes[i]>>4;if(this.currMask)for(let e=0;e<t.byteLength;e++)this.currMask[e>>5]&1<<(31&e)&&(t[e]=252)}fromPixels(t){let e=0;for(let i=108;i<this.b.byteLength;i++)this.dataBytes[i]=(15&t[e])+((15&t[e+1])<<4),e+=2}getPalette(t){return 0>t||t>14?0:this.dataBytes[88+t]}setPalette(t,e){0>t||t>14||(this.dataBytes[88+t]=e)}set title(t){this.utf16_encode(0,40,t)}get title(){return this.utf16_decode(0,40)}set creator(t){return Array.isArray(t)&&2===t.length?(this.creator=t[0],void(this.creator=t[1])):("string"==typeof t&&this.utf16_encode(44,18,t),void("number"==typeof t&&this.dataView.setUint16(42,t,!0)))}get creator(){return[this.utf16_decode(44,18),this.dataView.getUint16(42,!0),this.dataBytes[68]?"Male":"Female"]}set town(t){return Array.isArray(t)&&2===t.length?(this.town=t[0],void(this.town=t[1])):("string"==typeof t&&this.utf16_encode(66,18,t),void("number"==typeof t&&this.dataView.setUint16(64,t,!0)))}get town(){return[this.utf16_decode(66,18),this.dataView.getUint16(64,!0)]}set unknown_a(t){this.dataView.setUint16(86,t,!0)}get unknown_a(){return this.dataView.getUint16(86,!0)}setDefaultPalette(){for(let t=0;15>t;t++)this.dataBytes[88+t]=16*t+15}set unknown_b(t){this.dataBytes[103]=t}get unknown_b(){return this.dataBytes[103]}set unknown_c(t){this.dataBytes[104]=t}get unknown_c(){return this.dataBytes[104]}set patternType(t){if(this.width!==y.widthForType(t)){const e=new ArrayBuffer(y.widthForType(t)>32?2160:620),i=new DataView(e),s=new Uint8Array(e);for(let t=0;t<e.byteLength&&t<this.b.byteLength;++t)s[t]=this.dataBytes[t];this.dataView=i,this.dataBytes=s,this.b=e}this.dataBytes[105]=t,this.currMask=y.typeInfo[this.patternType]?y.typeInfo[this.patternType].mask:null}get patternType(){return this.dataBytes[105]}static getTypeStr(t){return y.typeInfo[t]&&y.typeInfo[t].name?y.typeInfo[t].name:"Unimplemented pattern type"}set unknown_d(t){this.dataView.setUint16(106,t,!0)}get unknown_d(){return this.dataView.getUint16(106,!0)}get width(){return y.typeInfo[this.dataBytes[105]]?y.typeInfo[this.dataBytes[105]].size:32}get height(){return y.typeInfo[this.dataBytes[105]]?y.typeInfo[this.dataBytes[105]].size:32}get byteLength(){return this.width>32?2160:620}pixelHash(){return g(this.b,88,this.width>32?2068:532)}fullHash(){return g(this.b,0,this.byteLength)}fixIssues(){this.creator[1]||(this.creator=60598),this.town[1]||(this.town=50500),this.dataBytes[84]=0,this.dataBytes[85]=0,this.dataBytes[62]>1&&(this.dataBytes[62]=0),this.dataBytes[63]=0,this.dataBytes[40]=0,this.dataBytes[41]=0}static widthForType(t){return y.typeInfo[t].size}static bytesForType(t){return this.widthForType(t)>32?2160:620}}y.paletteColors=["#FFEEFF","#FF99AA","#EE5599","#FF66AA","#FF0066","#BB4477","#CC0055","#990033","#552233","","","","","","","#FFFFFF","#FFBBCC","#FF7777","#DD3210","#FF5544","#FF0000","#CC6666","#BB4444","#BB0000","#882222","","","","","","","#EEEEEE","#DDCDBB","#FFCD66","#DD6622","#FFAA22","#FF6600","#BB8855","#DD4400","#BB4400","#663210","","","","","","","#DDDDDD","#FFEEDD","#FFDDCC","#FFCDAA","#FFBB88","#FFAA88","#DD8866","#BB6644","#995533","#884422","","","","","","","#CCCDCC","#FFCDFF","#EE88FF","#CC66DD","#BB88CC","#CC00FF","#996699","#8800AA","#550077","#330044","","","","","","","#BBBBBB","#FFBBFF","#FF99FF","#DD22BB","#FF55EE","#FF00CC","#885577","#BB0099","#880066","#550044","","","","","","","#AAAAAA","#DDBB99","#CCAA77","#774433","#AA7744","#993200","#773222","#552200","#331000","#221000","","","","","","","#999999","#FFFFCC","#FFFF77","#DDDD22","#FFFF00","#FFDD00","#CCAA00","#999900","#887700","#555500","","","","","","","#888888","#DDBBFF","#BB99EE","#6632CC","#9955FF","#6600FF","#554488","#440099","#220066","#221033","","","","","","","#777777","#BBBBFF","#8899FF","#3332AA","#3355EE","#0000FF","#333288","#0000AA","#101066","#000022","","","","","","","#666666","#99EEBB","#66CD77","#226610","#44AA33","#008833","#557755","#225500","#103222","#002210","","","","","","","#555555","#DDFFBB","#CCFF88","#88AA55","#AADD88","#88FF00","#AABB99","#66BB00","#559900","#336600","","","","","","","#444444","#BBDDFF","#77CDFF","#335599","#6699FF","#1077FF","#4477AA","#224477","#002277","#001044","","","","","","","#333233","#AAFFFF","#55FFFF","#0088BB","#55BBCC","#00CDFF","#4499AA","#006688","#004455","#002233","","","","","","","#222222","#CCFFEE","#AAEEDD","#33CDAA","#55EEBB","#00FFCC","#77AAAA","#00AA99","#008877","#004433","","","","","","","#000000","#AAFFAA","#77FF77","#66DD44","#00FF00","#22DD22","#55BB55","#00BB00","#008800","#224422","","","","","","",""],y.typeInfo=[],y.typeInfo[0]={name:"Dress, long sleeves",size:64,sections:[0,0,64,64]},y.typeInfo[1]={name:"Dress, short sleeves",size:64,sections:[0,0,64,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},y.typeInfo[2]={name:"Dress, sleeveless",size:64,sections:[0,0,64,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},y.typeInfo[3]={name:"Shirt, long sleeves",size:64,sections:[0,0,64,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]},y.typeInfo[4]={name:"Shirt, short sleeves",size:64,sections:[0,0,64,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-65536,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]},y.typeInfo[5]={name:"Shirt, sleeveless",size:64,sections:[0,0,64,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]},y.typeInfo[6]={name:"Hat with horns",size:32,sections:[0,0,32,32]},y.typeInfo[7]={name:"Hat without horns",size:32,sections:[0,0,32,32]},y.typeInfo[8]={name:"Standee",size:64,sections:[0,0,52,64],mask:[0,0,0,0,0,0,0,0,0,0,0,0,0,1069547520,-524288,-131072,-65536,-32768,-16384,-16384,-8192,-8192,-8192,-8192,-8192,-16384,-16384,-32768,-65536,-262144,-1048576,528482304,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048575,-1048569,-1048561,-1048545,-1048513,-1048513,-1048449,-1048449,-1048449,-1048449,-1048449,-1048513,-1048545,-1048545,-1048561,-1048573,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576,-1048576]},y.typeInfo[9]={name:"Normal pattern (easel)",size:32,sections:[0,0,32,32]},y.RGBLookup=[],y.YUVLookup=[];for(let t=0;256>t;t++){const e=y.paletteColors[t];if(7>e.length)y.RGBLookup.push(null),y.YUVLookup.push(null);else{const t=[Number.parseInt(e.slice(1,3),16),Number.parseInt(e.slice(3,5),16),Number.parseInt(e.slice(5,7),16)];y.RGBLookup.push(t),y.YUVLookup.push([.299*t[0]+.587*t[1]+.114*t[2],-.168736*t[0]+-.331264*t[1]+.5*t[2]+128,.5*t[0]+-.418688*t[1]+-.081312*t[2]+128])}}var w=y,b=i(3),m=i.n(b),F=i(13),B=i.n(F),x=async t=>{const e=await m.a.read(t),i=e.getWidth(),s=e.getHeight(),n=new Uint8ClampedArray(i*s*4);for(let t=0;s>t;t++)for(let s=0;i>s;s++){const r=m.a.intToRGBA(e.getPixelColor(s,t));n[4*(t*i+s)+0]=r.r,n[4*(t*i+s)+1]=r.g,n[4*(t*i+s)+2]=r.b,n[4*(t*i+s)+3]=r.a}return B()(n,i,s)},k=i(14),v=i.n(k),A=t=>!!t.authorTitle&&620===t.byteLength&&/^[\w ]+$/i.test(v()(t.authorTitle)),D=i(15),T=i.n(D),C=i(16),_=i.n(C),L=i(8),U=i.n(L),I=i(4),E=i.n(I),j=i(17),$=i.n(j);class S extends c{constructor(...t){super(...t),this.twit=null}async start(){this.options.text&&(this.template=U.a.compile(this.options.text,{noEscape:!0}));const t=await c.apiGot("credentials",{json:{handle:this.handle}}).json();this.twit=new $.a(t);const e={};this.options.track&&(e.track=this.options.track),this.options.language&&(e.language=this.options.language),this.twit.stream("statuses/filter",e).on("tweet",async t=>{if(!t.retweeted_status){if(t.flattenedText=_()(t.text),t.shortLink=`twitter.com/${t.user.screen_name}/status/${t.id_str}`,t.link=`https://${t.shortLink}`,t.authorTitle=a()(t.user.name)&&!t.user.name.includes("@")?t.user.name:t.user.screen_name,this.logger.debug(`@${t.user.screen_name}: ${t.flattenedText}`),!this.options.includeReplies&&t.in_reply_to_status_id)return void this.logger.debug("This is a reply, skipping");if(this.options.filter){const e=n()(this.options.filter);for(const i of e){const e=T()(i,"ensureRegex");if(e.discardRegex&&E()(e.discardRegex).test(t.flattenedText))return void this.logger.debug(`Positive test for ${e.discardRegex}, skipping`);if(e.ensureRegex&&!E()(e.ensureRegex).test(t.flattenedText))return void this.logger.debug(`Negative test for ${e.discardRegex}, skipping`)}}if(this.shouldHandleTweet){let e;try{e=await this.shouldHandleTweet(t)}catch(t){return void console.error(t)}if(!e)return void this.logger.debug("Skipped by shouldHandleTweet")}await this.handleTweet(t)}})}async handleTweet(t){await this.reactToTweet(t,{tweet:t})}async like(t){return this.dry?void this.logger.info(`Like ${t.shortLink}`):void await this.twit.post("favorites/create",{id:t.id_str})}async reply(t,e){return this.dry?void this.logger.info(`Reply to ${t.shortLink}: ${e}`):void await this.twit.post("statuses/update",{in_reply_to_status_id:t.id_str,status:this.options.text})}async retweet(t){return this.dry?void this.logger.info(`Retweet ${t.shortLink}`):void await this.twit.post(`statuses/retweet/${t.id_str}`)}async reactToTweet(t,e){if(this.options.reaction){if("tweet"===this.options.reaction&&this.template){const t=this.template(e);await this.post(t)}if("retweet"===this.options.reaction)if(this.template){const i=this.template(e);await this.post(`${i}\n${t.link}`)}else await this.retweet(t);if("like"===this.options.reaction&&await this.like(t),"reply"===this.options.reaction){const i=this.template(e);await this.reply(t,i)}}}}S.baseSchema={reaction:d.a.any(),includeReplies:d.a.boolean().default(!0),track:d.a.any(),language:d.a.any(),filter:d.a.any(),text:d.a.string()};class q extends S{async shouldHandleTweet(t){var e;if(Object(r.isEmpty)(null===(e=t.extended_entities)||void 0===e?void 0:e.media))return!1;for(const e of t.extended_entities.media)if("photo"!==e.type)return!1;const i=[];for(const e of t.extended_entities.media){var s;const t=await f()(e.media_url).buffer(),n=await x(t);if(null==n||null===(s=n.binaryData)||void 0===s||!s.length)continue;let r;try{r=new w(n.binaryData).toJson()}catch{continue}r.patternTypeTitle&&"Unimplemented pattern type"!==!r.patternTypeTitle&&A(r)&&i.push(r)}return!Object(r.isEmpty)(i)}}q.displayName="AnimalCrossingQrCodes",q.schema=d.a.object().keys({...S.baseSchema});var P=i(9),R=i.n(P),N=i(18),O=i.n(N),V=i(19),M=i.n(V),H=i(20),z=i.n(H),G=i(21),Q=i.n(G),Y=i(22),J=i.n(Y),K=new Intl.Collator(void 0);function W(t,e){return K.compare(t.title,e.title)}class X extends c{async start(){this.template=U.a.compile(this.options.template,{noEscape:!0}),this.options.cron||await this.run(),z.a.scheduleJob(this.options.cron,()=>{this.run()})}getPerkPool(){const t=Object.values(O.a.perks);return this.options.perksType?t.filter(t=>!!t.visible&&t.for===this.options.perksType):t.filter(t=>!!t.visible)}getPicks(){const t=this.getPerkPool(),e=Q()(t,{count:4});return e.sort(W),e}getText(t){return this.template({perks:M()(t.map(t=>t.title)),options:this.options})}async getBackgroundBuffer(){return await R.a.readFile(this.options.backgroundFile)}async run(){const t=this.getPicks(),e=t=>t.id,i=Array(t.length);for(let s=0;s<=t.length-1;s++)i[s]=e(t[s]);const s=await J()(i),n=await m.a.create(s),r=await this.getBackgroundBuffer(),a=await m.a.create(r);a.composite(n,0,0);const o=await a.getBase64Async(m.a.MIME_PNG);await this.post(this.getText(t),o)}}X.displayName="DeadByDaylightBuild",X.schema=d.a.object().keys({perksType:d.a.string(),cron:d.a.string(),backgroundFile:d.a.string().required(),template:d.a.string().default("Today's Dead by Daylight {{options.perksType}} build contains {{perks}}.")});var Z=i(23),tt=i.n(Z);class et extends S{async shouldHandleTweet(t){var e;if(Object(r.isEmpty)(null===(e=t.extended_entities)||void 0===e?void 0:e.media))return!1;for(const e of t.extended_entities.media)if("photo"!==e.type)return!1;const i=[];for(const e of t.extended_entities.media){const s=await f()(e.media_url).buffer(),n=await x(s);null!=n&&n.data&&/^\d{12}$/.test(n.data)&&(i.push(n.data),t.hasQrCode=!0)}if(!t.hasQrCode){var s;const e=/(?<code>(?:\d{4}[ -]?){2}\d{4})/.exec(t.flattenedText);if(null==e||null===(s=e.groups)||void 0===s?void 0:s.code){const t=e.groups.code.replace(/[ -]/g,"");this.logger.debug(`Extracted code: ${t}`),i.push(t)}}return!Object(r.isEmpty)(i)&&(t.codes=i,t.codesFormatted=i.map(t=>`${t.slice(0,4)} ${t.slice(4,8)} ${t.slice(8,12)}`),t.codesString=t.codesFormatted.split("\n"),!0)}async handleTweet(t){if(t.hasQrCode)return void await super.handleTweet(t);this.template(templateContext);const e=await tt.a.toDataURL();await this.post(`abc\n${t.codeString}`,e)}}et.displayName="PokemonGoQrCodes",et.schema=d.a.object().keys({...S.baseSchema});class it extends S{constructor(...t){super(...t),this.twit=null}async start(){this.options.reaction||(this.logger.warn("Option reaction not given, will default to retweet"),this.options.reaction="retweet"),await super.start(),this.checkQuotesRegex=E()(`/["„“'‚‘]${this.options.track}["„“'‚‘]/i`),this.checkLeadingLettersRegex=E()(`/\\w${this.options.track}/i`),this.checkTrailingLettersRegex=E()(`/${this.options.track}\\w/i`)}async shouldHandleTweet(t){return this.checkQuotesRegex.test(t.flattenedText)?(this.logger.debug("Found quotes, skipping (assuming author is not dumb)"),await this.like(t),!1):this.checkLeadingLettersRegex.test(t.flattenedText)?(this.logger.debug("Found leading letters, skipping (assuming false positive)"),!1):!this.checkTrailingLettersRegex.test(t.flattenedText)||(this.logger.debug("Found trailing letters, skipping (assuming false positive)"),!1)}}it.displayName="Spelling",it.schema=d.a.object().keys({...S.baseSchema});var st=i(10),nt=i(24),rt=i.n(nt),at=i(25),ot=i.n(at);class ht extends c{async start(){this.watcher=new ot.a({depotId:this.options.depotId}),this.watcher.on("contentChanged",async()=>{try{const t=await this.renderImage();h.c.info(t.slice(0,50)),await this.postMedia(t)}catch(t){h.c.error("Tweeter %s could not generate tweet: %s",this.id,t)}}),this.watcher.start(),h.c.info("Started watching on Steam depot %s (%s)",this.options.depotId,this.options.title)}async renderImage(){const t=Object(st.createCanvas)(1920,1080),e=t.getContext("2d");if(this.info.backgroundFile){let t=await R.a.readFile(this.info.backgroundFile);if(this.info.randomHue){const e=await m.a.read(t);e.color([{apply:"hue",params:[Math.random()*this.info.randomHue-this.info.randomHue/2]}]),t=await e.getBufferAsync("image/png")}const i=await Object(st.loadImage)(t);e.drawImage(i,0,0)}else e.fillStyle="#000",e.fillRect(0,0,1920,1080);e.fillStyle="#DDD",e.textAlign="center",e.textBaseline="top",e.font="240px Ubuntu",e.fillText("New Patch",960,300),e.fillStyle="#DDD",e.textAlign="center",e.textBaseline="top",e.font="60px Ubuntu",e.fillText(`in ${this.info.title}`,960,600);const i=rt()().format("MMMM DD, YYYY");return e.fillStyle="#DDD",e.textAlign="center",e.textBaseline="bottom",e.font="60px Ubuntu",e.fillText(i,960,290),t.toDataURL()}}ht.displayName="SteamGameUpdate";class lt extends c{async start(){this.post(`Tweeter Client v4.8.0, ${Date.now()}`)}}lt.displayName="Test";var ct={test:{Type:lt},steamGameUpdate:{Type:ht},deadByDaylightBuild:{Type:X},reaction:{Type:S},animalCrossingQrCodes:{Type:q},pokemonGoQrCodes:{Type:et},spelling:{Type:it}};class ut extends o.JaidCorePlugin{constructor(...t){super(...t),this.tweeters=[]}setCoreReference(t){this.core=t}async init(){c.initStatic();const t=n()(this.core.config.tweeters);if(Object(r.isEmpty)(t))this.log("No tweeters configured!");else{for(const{type:e,handle:i,dry:s,...n}of t){const t=ct[e];if(!t)return void this.logger.warn(`Unknown tweeter type ${e}`);const r=t.Type;let a=n;if(r.schema){const t=r.schema.validate(n);if(t.error)throw this.logger.warn(`Invalid configuration for tweeter type ${e}`),this.logger.warn(t.error.message),new Error(t.error.message);a=t.value}const o=new r(i,s,this.logger,a);if(!i)return void this.log(`Tweeter #${o.index} does not have a handle`);this.tweeters.push(o),this.log("Registered tweeter #%s (%s) for @%s",o.index,r.displayName,i)}for(const t of this.tweeters){var e;await(null===(e=t.start)||void 0===e?void 0:e.call(t))}}}}var dt=e.default=new ut}]);