@sarxina/sarxina-tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/twitch/TwitchChatManager.d.ts +18 -0
- package/dist/twitch/TwitchChatManager.d.ts.map +1 -0
- package/dist/twitch/TwitchChatManager.js +69 -0
- package/dist/twitch/TwitchChatManager.js.map +1 -0
- package/dist/twitch/index.d.ts +2 -0
- package/dist/twitch/index.d.ts.map +1 -0
- package/dist/twitch/index.js +2 -0
- package/dist/twitch/index.js.map +1 -0
- package/dist/vts/index.d.ts +2 -0
- package/dist/vts/index.d.ts.map +1 -0
- package/dist/vts/index.js +2 -0
- package/dist/vts/index.js.map +1 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class TwitchChatManager {
|
|
2
|
+
private chatClient;
|
|
3
|
+
private apiClient;
|
|
4
|
+
private eventListener;
|
|
5
|
+
private chatCallbacks;
|
|
6
|
+
private redeemCallbacks;
|
|
7
|
+
constructor(msgCallback: (message: string, chatter: string) => void);
|
|
8
|
+
registerNewChatCallback: (callback: (message: string, chatter: string) => void) => void;
|
|
9
|
+
registerNewRedeemCallback: (callback: (chatter: string, input: string, cost: number) => void) => void;
|
|
10
|
+
private setupTwitchConnection;
|
|
11
|
+
say: (message: string) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare class ChatCommandManager {
|
|
14
|
+
private chatManager;
|
|
15
|
+
private command;
|
|
16
|
+
constructor(command: string, msgCallback: (subcommand: string, chatter: string) => void, chatManager: TwitchChatManager);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=TwitchChatManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TwitchChatManager.d.ts","sourceRoot":"","sources":["../../src/twitch/TwitchChatManager.ts"],"names":[],"mappings":"AASA,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,aAAa,CAAgD;IACrE,OAAO,CAAC,eAAe,CAA4D;gBAIvE,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI;IAMnE,uBAAuB,GAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,UAE9E;IAED,yBAAyB,GAAI,UAAU,CACnC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,KAAK,IAAI,UAExB;IAED,OAAO,CAAC,qBAAqB,CAgC5B;IAED,GAAG,GAAU,SAAS,MAAM,mBAE3B;CACJ;AAGD,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,OAAO,CAAQ;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,EAC1D,WAAW,EAAE,iBAAiB;CAgBrC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ChatClient } from "@twurple/chat";
|
|
2
|
+
import { StaticAuthProvider } from "@twurple/auth";
|
|
3
|
+
import { EventSubWsListener } from "@twurple/eventsub-ws";
|
|
4
|
+
import { ApiClient } from "@twurple/api";
|
|
5
|
+
// Manager class that listens for both chat messages and channel point redeems
|
|
6
|
+
// Firing registered callbacks on a hit
|
|
7
|
+
export class TwitchChatManager {
|
|
8
|
+
chatClient;
|
|
9
|
+
apiClient;
|
|
10
|
+
eventListener;
|
|
11
|
+
chatCallbacks;
|
|
12
|
+
redeemCallbacks;
|
|
13
|
+
// TODO: make the constructor not have to take an inital callback
|
|
14
|
+
// This is to lwork with old versions of the manager
|
|
15
|
+
constructor(msgCallback) {
|
|
16
|
+
this.chatCallbacks = [];
|
|
17
|
+
this.redeemCallbacks = [];
|
|
18
|
+
this.setupTwitchConnection(msgCallback);
|
|
19
|
+
}
|
|
20
|
+
registerNewChatCallback = (callback) => {
|
|
21
|
+
this.chatCallbacks.push(callback);
|
|
22
|
+
};
|
|
23
|
+
registerNewRedeemCallback = (callback) => {
|
|
24
|
+
this.redeemCallbacks.push(callback);
|
|
25
|
+
};
|
|
26
|
+
setupTwitchConnection = async (msgCallback) => {
|
|
27
|
+
const authProvider = new StaticAuthProvider(process.env.TWITCH_CLIENT_ID, process.env.TWITCH_ACCESS_TOKEN);
|
|
28
|
+
this.chatClient = new ChatClient({
|
|
29
|
+
authProvider,
|
|
30
|
+
channels: [process.env.TWITCH_CHANNEL_NAME]
|
|
31
|
+
});
|
|
32
|
+
this.apiClient = new ApiClient({ authProvider: authProvider });
|
|
33
|
+
this.eventListener = new EventSubWsListener({ apiClient: this.apiClient });
|
|
34
|
+
this.chatCallbacks.push(msgCallback);
|
|
35
|
+
// Check all of the message callbacks
|
|
36
|
+
this.chatClient.onMessage((channel, user, message) => {
|
|
37
|
+
this.chatCallbacks.forEach(cb => cb(message, user));
|
|
38
|
+
});
|
|
39
|
+
// Check all the channel redemption callbacks
|
|
40
|
+
this.eventListener.onChannelRedemptionAdd(process.env.TWITCH_BROADCASTER_ID, (event) => {
|
|
41
|
+
this.redeemCallbacks.forEach(cb => cb(event.userDisplayName, event.input, event.rewardCost));
|
|
42
|
+
});
|
|
43
|
+
this.eventListener.start();
|
|
44
|
+
this.chatClient.connect();
|
|
45
|
+
console.log("Connected to Twitch Chat");
|
|
46
|
+
};
|
|
47
|
+
say = async (message) => {
|
|
48
|
+
await this.chatClient.say(process.env.TWITCH_CHANNEL_NAME, message);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Class that handles a single command
|
|
52
|
+
export class ChatCommandManager {
|
|
53
|
+
chatManager;
|
|
54
|
+
command;
|
|
55
|
+
constructor(command, msgCallback, chatManager) {
|
|
56
|
+
this.command = command;
|
|
57
|
+
this.chatManager = chatManager;
|
|
58
|
+
// Create funciton that strips the command sends the subcommand
|
|
59
|
+
const subcommandCallback = (message, chatter) => {
|
|
60
|
+
const frontString = message.split(' ')[0];
|
|
61
|
+
const subcommand = message.includes(" ") ? message.slice(message.indexOf(" ") + 1) : "";
|
|
62
|
+
if (frontString === this.command) {
|
|
63
|
+
msgCallback(subcommand, chatter);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.chatManager.registerNewChatCallback(subcommandCallback);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=TwitchChatManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TwitchChatManager.js","sourceRoot":"","sources":["../../src/twitch/TwitchChatManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,8EAA8E;AAC9E,uCAAuC;AACvC,MAAM,OAAO,iBAAiB;IAClB,UAAU,CAAa;IACvB,SAAS,CAAY;IACrB,aAAa,CAAqB;IAClC,aAAa,CAAgD;IA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GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAExF,IAAI,WAAW,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC/B,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACrC,CAAC;QACL,CAAC,CAAA;QACD,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IACjE,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/twitch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/twitch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vts/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sarxina/sarxina-tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared streaming utilities — Twitch chat manager, VTube Studio client, etc.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./twitch": {
|
|
14
|
+
"types": "./dist/twitch/index.d.ts",
|
|
15
|
+
"import": "./dist/twitch/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./vts": {
|
|
18
|
+
"types": "./dist/vts/index.d.ts",
|
|
19
|
+
"import": "./dist/vts/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@twurple/auth": "^7.4.0",
|
|
27
|
+
"@twurple/chat": "^7.4.0",
|
|
28
|
+
"@twurple/api": "^7.4.0",
|
|
29
|
+
"@twurple/eventsub-ws": "^7.4.0",
|
|
30
|
+
"@twurple/eventsub-base": "^7.4.0",
|
|
31
|
+
"ws": "^8.16.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.6.0",
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
36
|
+
"@types/ws": "^8.5.10"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Sarxina/sarxina-tools.git"
|
|
44
|
+
},
|
|
45
|
+
"author": "Sarxina",
|
|
46
|
+
"license": "ISC",
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"clean": "rm -rf dist"
|
|
50
|
+
}
|
|
51
|
+
}
|