Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
IT LIVESSSSSSSSSS (krn waz here) @kcoderhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspermayone committed Jul 3, 2024
1 parent 3419044 commit 7527ac2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
34 changes: 34 additions & 0 deletions src/functions/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { blog } from "../util/Logger";
let hcTeam = "T0266FRGM";
let hcChannel_purplebubble = "C068D2P46TH";
let hcChannel_pbip = "C06AXC7B0QN";
let hcmirrorTest = "C069N64PW4A";
let pbmirrorTest = "C07ASSJGE2G";
let pbTeam = "T07986PHP2R";
let pbChannel_pb = "C079B7H3AKD";
let pbChannel_pbpb = "C078WH9B44F";

const channels = [
hcChannel_pbip,
hcChannel_purplebubble,
hcmirrorTest,
pbmirrorTest,
pbChannel_pb,
pbChannel_pbpb,
];
Expand Down Expand Up @@ -53,6 +57,21 @@ export async function mirror(pbClient, hcClient, message) {
let userRealName = profile.real_name!;

switch (messageChannel) {
case pbmirrorTest:
blog(
`Message sent #mirrorTest (PB) => #mirrorTest (HC): ${message.text}`,
"info"
);

hcClient.chat.postMessage({
username: userRealName,
icon_url: userpfp,
channel: hcmirrorTest,
text: message.text,
blocks: message.blocks,
});

break;
case pbChannel_pbpb:
blog(
`Message sent #pb-pb (PB) => #pbip (HC): ${message.text}`,
Expand Down Expand Up @@ -98,6 +117,21 @@ export async function mirror(pbClient, hcClient, message) {
let userRealName = profile.real_name!;

switch (messageChannel) {
case hcmirrorTest:
blog(
`Message sent #mirrorTest (HC) => #mirrorTest (PB): ${message.text}`,
"info"
);

pbClient.chat.postMessage({
username: userRealName,
icon_url: userpfp,
channel: pbmirrorTest,
text: message.text,
blocks: message.blocks,
});

break;
case hcChannel_purplebubble:
blog(
`Message sent #purplebubble (HC) => #pb (PB): ${message.text}`,
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const HCapp = new SlackApp({
const PBclient: SlackAPIClient = PBapp.client;
const HCclient: SlackAPIClient = HCapp.client;

PBapp.anyMessage(async ({ payload, context }) => {
await mirror(PBclient, HCclient, payload);
});
HCapp.anyMessage(async ({ payload, context }) => {
await mirror(PBclient, HCclient, payload);
});
Expand Down
15 changes: 6 additions & 9 deletions src/util/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import { PBclient } from "../index";
import async from "async";
import Bottleneck from "bottleneck";
import colors from "colors";
import { ChatPostMessageRequest } from "slack-edge";

// Create a rate limiter with Bottleneck
const limiter = new Bottleneck({
minTime: 1000, // 1 second between each request
});

const messageQueue = async.queue(async (task, callback) => {
try {
const messageQueue = async.queue(
async (task: ChatPostMessageRequest, callback) => {
await limiter.schedule(() => PBclient.chat.postMessage(task));
callback();
} catch (error) {
console.error("Error posting message:", error);
// @ts-ignore
callback(error);
}
}, 1); // Only one worker to ensure order and rate limit
},
1
); // Only one worker to ensure order and rate limit

async function slog(logMessage, type) {
const message = {
Expand Down

0 comments on commit 7527ac2

Please sign in to comment.