Skip to content

Commit bcf2b09

Browse files
committed
small update
1 parent 4f1ad46 commit bcf2b09

8 files changed

Lines changed: 103 additions & 278 deletions

File tree

bun.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@twurple/eventsub-ws": "^8.0.2",
1919
"@types/compression": "^1.8.1",
2020
"@types/cookie-parser": "^1.4.10",
21+
"@types/cors": "^2.8.19",
2122
"@types/express-fileupload": "^1.5.1",
2223
"@types/fabric": "^5.3.10",
2324
"@types/grpc-error": "^1.0.3",
@@ -26,6 +27,7 @@
2627
"body-parser": "^2.2.1",
2728
"compression": "^1.8.1",
2829
"cookie-parser": "^1.4.7",
30+
"cors": "^2.8.5",
2931
"discord.js": "^14.25.1",
3032
"dotenv": "^17.2.3",
3133
"entities": "^7.0.0",

src/app.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DiscordAuthData, TalkingBot } from "./talkingbot";
99
import { sign, verify } from "jsonwebtoken";
1010
import { getTTSSounds } from "./tts";
1111
import fileUpload, { UploadedFile } from "express-fileupload";
12+
import cors from "cors";
1213
import { getDiscordUserId, isDiscordAuthData } from "./util";
1314
import { handleKofiEvent, isKofiEvent } from "./kofi";
1415
import { MessageData } from "botModule";
@@ -24,6 +25,7 @@ app.use(express.static("public"));
2425
app.use(express.static("config/sounds"));
2526
app.use(express.static("config/images"));
2627
app.use(bodyParser.text());
28+
app.use(cors());
2729
app.use(cookieParser());
2830
app.use(express.urlencoded({ extended: true }));
2931
app.use(
@@ -404,10 +406,6 @@ app.get("/creditsList", (_req, res) => {
404406
res.send(bot.credits.getCreditsList());
405407
});
406408

407-
app.get("/credits", (_req, res) => {
408-
res.sendFile(__dirname + "/html/credits.html");
409-
});
410-
411409
app.get("/tts", (_req: Request, res: Response) => {
412410
res.sendFile(__dirname + "/html/tts.html");
413411
});

src/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ export class MessageHandler {
12931293
data.color = user.color ?? data.color;
12941294

12951295
if (data.isUserMod)
1296-
this.bot.credits.addToCredits(data.username, CreditType.Moderator);
1297-
this.bot.credits.addToCredits(data.username, CreditType.Chatter);
1296+
this.bot.credits.addToCredits(data.id,data.sender,data.color, CreditType.Moderator);
1297+
this.bot.credits.addToCredits(data.id,data.sender,data.color, CreditType.Chatter);
12981298

12991299
if (this.bot.twitch.isStreamOnline) addRecentChatter(this.bot, data);
13001300

src/credits.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { TalkingBot } from "./talkingbot";
22

3+
export interface Chatter {
4+
name: string,
5+
color: string,
6+
}
7+
38
interface CreditsList {
4-
followers: string[];
5-
subscribers: string[];
6-
moderators: string[];
7-
cheers: string[];
8-
chatters: string[];
9-
whereWordWinner?: string;
9+
followers: Chatter[];
10+
subscribers: Chatter[];
11+
moderators: Chatter[];
12+
cheers: Chatter[];
13+
chatters: Chatter[];
1014
}
1115

1216
export enum CreditType {
@@ -18,11 +22,12 @@ export enum CreditType {
1822
}
1923

2024
export class Credits {
21-
private followers: Set<string> = new Set();
22-
private subscribers: Set<string> = new Set();
23-
private moderators: Set<string> = new Set();
24-
private cheers: Set<string> = new Set();
25-
private chatters: Set<string> = new Set();
25+
private followers: Map<string,Chatter> = new Map();
26+
private subscribers: Map<string,Chatter> = new Map();
27+
28+
private moderators: Map<string,Chatter> = new Map();
29+
private cheers: Map<string,Chatter> = new Map();
30+
private chatters:Map<string,Chatter> = new Map();
2631
private bot: TalkingBot;
2732

2833
constructor(bot: TalkingBot) {
@@ -37,22 +42,22 @@ export class Credits {
3742
this.chatters.clear();
3843
}
3944

40-
public addToCredits(name: string, type: CreditType) {
45+
public addToCredits(id: string,name: string,color: string, type: CreditType) {
4146
switch (type) {
4247
case CreditType.Follow:
43-
this.followers.add(name);
48+
this.followers.set(id,{name,color});
4449
break;
4550
case CreditType.Moderator:
46-
this.moderators.add(name);
51+
this.moderators.set(id,{name,color})
4752
break;
4853
case CreditType.Subscription:
49-
this.subscribers.add(name);
54+
this.subscribers.set(id,{name,color})
5055
break;
5156
case CreditType.Cheer:
52-
this.cheers.add(name);
57+
this.cheers.set(id,{name,color})
5358
break;
5459
case CreditType.Chatter:
55-
this.chatters.add(name);
60+
this.chatters.set(id,{name,color});
5661
break;
5762
}
5863
}
@@ -66,12 +71,11 @@ export class Credits {
6671

6772
public getCreditsList(): string {
6873
const list: CreditsList = {
69-
followers: Array.from(this.followers),
70-
subscribers: Array.from(this.subscribers),
71-
moderators: Array.from(this.moderators),
72-
cheers: Array.from(this.cheers),
73-
chatters: Array.from(this.chatters),
74-
whereWordWinner: this.bot.whereWord.getWinner()?.name,
74+
followers: Array.from(this.followers.values()),
75+
subscribers: Array.from(this.subscribers.values()),
76+
moderators: Array.from(this.moderators.values()),
77+
cheers: Array.from(this.cheers.values()),
78+
chatters: Array.from(this.chatters.values()),
7579
};
7680
return JSON.stringify(list);
7781
}

src/html/chat.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
const searchParams = new URLSearchParams(queryString);
4747
const showCommands = searchParams.get("showcmd") === "yes";
4848
const showEmoteWall = searchParams.get("emotewall") === "sure";
49+
const transparent = searchParams.has("transparent");
50+
if(transparent)
51+
messageList.style.backgroundColor = "rgba(0,0,0,0)";
4952

5053
const currentEmotes = [];
5154

@@ -456,7 +459,7 @@
456459
"",
457460
);
458461
replyTo = msg.parentMessageUserDisplayName;
459-
replyId = msg.parentMessageUserId;
462+
replyId = `twitch-${msg.parentMessageUserId}`;
460463
replyText = msg.parentMessageText;
461464
}
462465

@@ -470,7 +473,6 @@
470473
indexes.push(parseInt(index));
471474
});
472475
});
473-
console.log(indexes);
474476

475477
const isUserMod = msg.userInfo.isMod || msg.userInfo.isBroadcaster;
476478
const isUserVip = isUserMod || msg.userInfo.isVip;
@@ -500,7 +502,6 @@
500502
id: `twitch-${msg.id}`,
501503
};
502504
addToMessageList(message);
503-
console.log(message);
504505
}
505506
async function getMessages() {
506507
console.log("getting new messages.");
@@ -512,7 +513,6 @@
512513
messages.messages.forEach((msg) => {
513514
if (!msg.includes("PRIVMSG")) return;
514515
const message = parseTwitchMessage(msg);
515-
console.log(message);
516516
const isCommand =
517517
message.text.startsWith("!") ||
518518
message.userInfo.userId === "736013381" ||
@@ -637,7 +637,6 @@
637637
}
638638
body {
639639
margin: 0px;
640-
background-color: #2b2e38;
641640
}
642641
.redeem {
643642
color: #a5a5a5;

0 commit comments

Comments
 (0)