@curatedotfun/discord
Version:
Discord plugin for curatedotfun
2 lines • 3.92 kB
JavaScript
;exports.ids=["768"],exports.modules={747:function(e,n,t){t.r(n),t.d(n,{default:()=>c});var r=t(349);function i(e,n,t,r,i,o,a){try{var s=e[o](a),l=s.value}catch(e){t(e);return}s.done?n(l):Promise.resolve(l).then(r,i)}function o(e){return function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function s(e){i(a,r,o,s,l,"next",e)}function l(e){i(a,r,o,s,l,"throw",e)}s(void 0)})}}function a(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function s(e,n){return null!=n&&"undefined"!=typeof Symbol&&n[Symbol.hasInstance]?!!n[Symbol.hasInstance](e):e instanceof n}function l(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){var l=[o,s];if(t)throw TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&l[0]?r.return:l[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,l[1])).done)return i;switch(r=0,i&&(l=[2&l[0],i.value]),l[0]){case 0:case 1:i=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!i||l[1]>i[0]&&l[1]<i[3])){a.label=l[1];break}if(6===l[0]&&a.label<i[1]){a.label=i[1],i=l;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(l);break}i[2]&&a.ops.pop(),a.trys.pop();continue}l=n.call(e,a)}catch(e){l=[6,e],r=0}finally{t=i=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}var c=function(){var e;function n(){if(!(this instanceof n))throw TypeError("Cannot call a class as a function");a(this,"type","distributor"),a(this,"client",null),a(this,"channelId",null),a(this,"botToken",null)}return e=[{key:"initialize",value:function(e){var n=this;return o(function(){var t,i;return l(this,function(o){switch(o.label){case 0:if(!e)throw Error("Discord plugin requires configuration.");if(!e.botToken)throw Error("Discord plugin requires botToken");if(!e.channelId)throw Error("Discord plugin requires channelId");n.botToken=e.botToken,n.channelId=e.channelId,console.log("config",e),o.label=1;case 1:return o.trys.push([1,4,,5]),n.client=new r.Client({intents:[r.GatewayIntentBits.Guilds,r.GatewayIntentBits.GuildMessages,r.GatewayIntentBits.MessageContent]}),[4,n.client.login(n.botToken)];case 2:return o.sent(),[4,n.client.channels.fetch(n.channelId)];case 3:if(!(t=o.sent())||!s(t,r.TextChannel))throw Error("Invalid channel ID or insufficient permissions");return[3,5];case 4:throw console.error("Failed to initialize Discord plugin:",i=o.sent()),i;case 5:return[2]}})})()}},{key:"distribute",value:function(e){var n=e.input,t=this;return o(function(){var e,i;return l(this,function(o){switch(o.label){case 0:if(!t.client||!t.channelId)throw Error("Discord plugin not initialized");o.label=1;case 1:return o.trys.push([1,4,,5]),[4,t.client.channels.fetch(t.channelId)];case 2:if(!(e=o.sent())||!s(e,r.TextChannel))throw Error("Invalid channel ID or insufficient permissions");return[4,e.send(n)];case 3:return o.sent(),[3,5];case 4:throw console.error("Failed to send message to Discord:",i=o.sent()),i;case 5:return[2]}})})()}},{key:"cleanup",value:function(){var e=this;return o(function(){return l(this,function(n){switch(n.label){case 0:if(!e.client)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,e.client.destroy()];case 2:return n.sent(),[3,4];case 3:return console.error("Error during Discord cleanup:",n.sent()),[3,4];case 4:return[2]}})})()}}],function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,e),n}()}};
//# sourceMappingURL=768.js.map