custom record stuff
This commit is contained in:
parent
fd0d598f4c
commit
f15283cb7f
4 changed files with 43 additions and 76 deletions
|
|
@ -1,17 +0,0 @@
|
|||
import 'package:tmi/tmi.dart';
|
||||
import "package:riverpod/riverpod.dart";
|
||||
|
||||
class ClientController extends Notifier<Client> {
|
||||
@override
|
||||
Client build() {
|
||||
final client = Client(channels: "cozyp62", secure: true)
|
||||
..connect()
|
||||
..on("disconnected", (reason) => ref.invalidateSelf());
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
static final provider = NotifierProvider<ClientController, Client>(
|
||||
ClientController.new,
|
||||
);
|
||||
}
|
||||
|
|
@ -1,18 +1,51 @@
|
|||
import "package:cozybot/controllers/client_controller.dart";
|
||||
import "dart:convert";
|
||||
import "dart:io";
|
||||
import "package:riverpod/riverpod.dart";
|
||||
|
||||
class RecordController extends Notifier<String> {
|
||||
@override
|
||||
String build() {
|
||||
ref.watch(ClientController.provider).on("chat", (_, userstate, message, _) {
|
||||
if (userstate["username"] == "streamlabs") {
|
||||
final match = RegExp(
|
||||
r"\d+[Ww]?-\d+[Ll]?",
|
||||
).allMatches(message).lastOrNull;
|
||||
final group = match?.group(0);
|
||||
if (group == null) return;
|
||||
state = "Record:\n$group";
|
||||
}
|
||||
print("aa");
|
||||
WebSocket.connect("wss://irc-ws.chat.twitch.tv:443").then((ws) {
|
||||
void send(String data) => ws.add("$data\n\r");
|
||||
|
||||
send("NICK justinfan12345");
|
||||
send("JOIN #cozyp62");
|
||||
print("Logged in...");
|
||||
|
||||
ws.listen(
|
||||
(text) {
|
||||
for (final line in const LineSplitter().convert(text)) {
|
||||
if (line.startsWith("PING")) {
|
||||
return send("PONG :tmi.twitch.tv");
|
||||
}
|
||||
|
||||
if (!line.contains(" PRIVMSG #")) return;
|
||||
|
||||
// Parse user from ":user!user@user.tmi.twitch.tv ..."
|
||||
if (!line.startsWith(":")) continue;
|
||||
final bang = line.indexOf("!");
|
||||
if (bang == -1) return;
|
||||
final user = line.substring(1, bang);
|
||||
|
||||
// Parse message after " :"
|
||||
final msgStart = line.indexOf(" :");
|
||||
if (msgStart == -1) return;
|
||||
final message = line.substring(msgStart + 2);
|
||||
|
||||
if (user != "streamlabs") return;
|
||||
|
||||
final match = RegExp(
|
||||
r"\d+[Ww]?-\d+[Ll]?",
|
||||
).allMatches(message).lastOrNull;
|
||||
final group = match?.group(0);
|
||||
if (group == null) return;
|
||||
state = "Record:\n$group";
|
||||
}
|
||||
},
|
||||
onDone: ref.invalidateSelf,
|
||||
onError: (_) => ref.invalidateSelf(),
|
||||
);
|
||||
});
|
||||
|
||||
return "Record:\n0-0";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue