2021-12-15 23:54:06 -05:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2021-12-31 20:39:58 -05:00
|
|
|
import 'package:collection/collection.dart';
|
2022-01-05 15:11:37 -05:00
|
|
|
import 'package:flutter/gestures.dart';
|
2021-12-15 23:54:06 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2022-01-01 00:58:06 -05:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-01-12 13:55:49 -05:00
|
|
|
import 'package:frosty/models/badges.dart';
|
2021-12-15 23:54:06 -05:00
|
|
|
import 'package:frosty/models/emotes.dart';
|
2022-01-07 21:56:45 -05:00
|
|
|
import 'package:frosty/screens/channel/stores/chat_assets_store.dart';
|
2022-01-11 11:01:10 -05:00
|
|
|
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
2021-12-29 19:54:32 -05:00
|
|
|
import 'package:intl/intl.dart';
|
2022-01-05 15:11:37 -05:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2021-12-15 23:54:06 -05:00
|
|
|
|
|
|
|
|
/// The object representation of a Twitch IRC message.
|
|
|
|
|
class IRCMessage {
|
2022-01-12 16:03:37 -05:00
|
|
|
final String raw;
|
2022-01-12 12:20:02 -05:00
|
|
|
Command command;
|
2021-12-15 23:54:06 -05:00
|
|
|
final Map<String, String> tags;
|
|
|
|
|
final String? user;
|
2022-01-12 12:20:02 -05:00
|
|
|
final Map<String, Emote>? localEmotes;
|
2021-12-15 23:54:06 -05:00
|
|
|
String? message;
|
2022-01-12 12:20:02 -05:00
|
|
|
List<String>? split;
|
|
|
|
|
bool? action;
|
|
|
|
|
bool? mention;
|
2021-12-15 23:54:06 -05:00
|
|
|
|
|
|
|
|
IRCMessage({
|
2022-01-12 16:03:37 -05:00
|
|
|
required this.raw,
|
2021-12-15 23:54:06 -05:00
|
|
|
required this.command,
|
2022-01-12 12:20:02 -05:00
|
|
|
required this.tags,
|
|
|
|
|
this.user,
|
|
|
|
|
this.localEmotes,
|
|
|
|
|
this.message,
|
|
|
|
|
this.split,
|
|
|
|
|
this.action,
|
|
|
|
|
this.mention,
|
2021-12-15 23:54:06 -05:00
|
|
|
});
|
|
|
|
|
|
2021-12-16 00:06:28 -05:00
|
|
|
/// Returns a list of messages where the gievn CLEARCHAT message is applied.
|
|
|
|
|
static List<IRCMessage> clearChat({required List<IRCMessage> messages, required IRCMessage ircMessage}) {
|
|
|
|
|
// If there is no message, it means that entire chat was cleared.
|
|
|
|
|
if (ircMessage.message == null) {
|
|
|
|
|
messages.clear();
|
|
|
|
|
messages.add(IRCMessage.createNotice(message: 'Chat was cleared by a moderator'));
|
|
|
|
|
return messages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final bannedUser = ircMessage.message;
|
|
|
|
|
final banDuration = ircMessage.tags['ban-duration'];
|
|
|
|
|
|
|
|
|
|
// Search the messages for the banned/timed-out user.
|
|
|
|
|
messages.asMap().forEach((i, message) {
|
|
|
|
|
if (message.user == bannedUser) {
|
|
|
|
|
// Mark the message for removal.
|
|
|
|
|
messages[i].command = Command.clearChat;
|
|
|
|
|
|
|
|
|
|
// If timed-out, indicate the duration.
|
|
|
|
|
if (banDuration != null) {
|
|
|
|
|
messages[i].tags['ban-duration'] = banDuration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns a list of messages where the gievn CLEARMSG message is applied.
|
|
|
|
|
static List<IRCMessage> clearMessage({required List<IRCMessage> messages, required IRCMessage ircMessage}) {
|
|
|
|
|
final targetId = ircMessage.tags['target-msg-id'];
|
|
|
|
|
|
|
|
|
|
// Search for the message associated with the ID and mark the message for deletion.
|
|
|
|
|
for (var i = 0; i < messages.length; i++) {
|
|
|
|
|
if (messages[i].tags['id'] == targetId) {
|
|
|
|
|
messages[i].command = Command.clearMessage;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 23:54:06 -05:00
|
|
|
/// Returns an [InlineSpan] list that corresponds to the badges, username, words, and emotes of the given [IRCMessage].
|
|
|
|
|
List<InlineSpan> generateSpan({
|
2021-12-29 19:54:32 -05:00
|
|
|
required TextStyle? style,
|
2022-01-07 12:42:15 -05:00
|
|
|
required ChatAssetsStore assetsStore,
|
2022-01-11 20:58:30 -05:00
|
|
|
required double badgeHeight,
|
|
|
|
|
required double emoteHeight,
|
2022-01-16 12:39:20 -05:00
|
|
|
required bool isLightTheme,
|
2022-01-06 23:06:25 -05:00
|
|
|
bool showMessage = true,
|
|
|
|
|
bool useZeroWidth = false,
|
2022-01-06 09:32:39 -05:00
|
|
|
bool useReadableColors = false,
|
2022-01-11 11:01:10 -05:00
|
|
|
TimestampType timestamp = TimestampType.disabled,
|
2021-12-15 23:54:06 -05:00
|
|
|
}) {
|
2022-01-07 12:42:15 -05:00
|
|
|
final emoteToObject = assetsStore.emoteToObject;
|
|
|
|
|
final twitchBadgeToObject = assetsStore.twitchBadgesToObject;
|
|
|
|
|
final ffzUserToBadges = assetsStore.userToFFZBadges;
|
|
|
|
|
final sevenTVUserToBadges = assetsStore.userTo7TVBadges;
|
|
|
|
|
final bttvUserToBadge = assetsStore.userToBTTVBadges;
|
|
|
|
|
final ffzRoomInfo = assetsStore.ffzRoomInfo;
|
|
|
|
|
|
2021-12-15 23:54:06 -05:00
|
|
|
// The span list that will be used to render the chat message
|
|
|
|
|
final span = <InlineSpan>[];
|
|
|
|
|
|
2022-01-11 11:01:10 -05:00
|
|
|
if (timestamp != TimestampType.disabled) {
|
2021-12-29 19:54:32 -05:00
|
|
|
final time = tags['tmi-sent-ts'] ?? DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
final parsedTime = DateTime.fromMillisecondsSinceEpoch(int.parse(time));
|
|
|
|
|
|
2022-01-11 11:01:10 -05:00
|
|
|
if (timestamp == TimestampType.twentyFour) {
|
2021-12-29 19:54:32 -05:00
|
|
|
span.add(
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: '${DateFormat.Hm().format(parsedTime)} ',
|
|
|
|
|
style: style?.copyWith(color: style.color?.withOpacity(0.5)),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 11:01:10 -05:00
|
|
|
if (timestamp == TimestampType.twelve) {
|
2021-12-29 19:54:32 -05:00
|
|
|
span.add(
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: '${DateFormat('h:mm').format(parsedTime)} ',
|
|
|
|
|
style: style?.copyWith(color: style.color?.withOpacity(0.5)),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 03:45:00 -05:00
|
|
|
// Indicator to skip adding the bot badges later when adding the rest of FFZ badges.
|
|
|
|
|
var skipBot = false;
|
2021-12-30 23:00:03 -05:00
|
|
|
|
2022-01-07 12:42:15 -05:00
|
|
|
final ffzUserBadges = ffzUserToBadges[tags['user-id']];
|
2022-01-02 03:45:00 -05:00
|
|
|
final twitchBadges = tags['badges']?.split(',');
|
|
|
|
|
// Pasrse and add the Twitch badges to the span if they exist.
|
|
|
|
|
if (twitchBadges != null) {
|
|
|
|
|
for (final badge in twitchBadges) {
|
|
|
|
|
final badgeInfo = twitchBadgeToObject[badge];
|
|
|
|
|
if (badgeInfo != null) {
|
2022-01-12 09:29:31 -05:00
|
|
|
var badgeUrl = badgeInfo.url;
|
2021-12-31 21:03:19 -05:00
|
|
|
|
2022-01-02 03:45:00 -05:00
|
|
|
// Add custom FFZ mod badge if it exists.
|
2022-01-12 09:29:31 -05:00
|
|
|
if (badgeInfo.name == 'Moderator' && (ffzUserBadges != null || ffzRoomInfo?.modUrls != null)) {
|
2022-01-02 03:45:00 -05:00
|
|
|
// Check if mod is bot.
|
2022-01-12 09:29:31 -05:00
|
|
|
final botBadge = ffzUserBadges?.firstWhereOrNull((element) => element.name == 'Bot');
|
2021-12-31 20:39:58 -05:00
|
|
|
|
2022-01-02 17:53:25 -05:00
|
|
|
// Check if user has bot badge or room has custom FFZ mod badges
|
2022-01-02 03:45:00 -05:00
|
|
|
if (botBadge != null) {
|
2022-01-12 13:55:49 -05:00
|
|
|
badgeUrl = botBadge.url;
|
2022-01-02 03:45:00 -05:00
|
|
|
skipBot = true;
|
2022-01-02 17:53:25 -05:00
|
|
|
} else if (ffzRoomInfo?.modUrls != null) {
|
2022-01-02 03:45:00 -05:00
|
|
|
badgeUrl = 'https:' + (ffzRoomInfo!.modUrls?.url4x ?? ffzRoomInfo.modUrls?.url2x ?? ffzRoomInfo.modUrls!.url1x);
|
|
|
|
|
}
|
2021-12-31 21:03:19 -05:00
|
|
|
|
2022-01-12 13:55:49 -05:00
|
|
|
final newBadge = Badge(
|
|
|
|
|
name: skipBot ? 'Moderator (Bot)' : 'Moderator',
|
|
|
|
|
url: badgeUrl,
|
|
|
|
|
type: BadgeType.twitch,
|
|
|
|
|
);
|
|
|
|
|
|
2022-01-02 03:45:00 -05:00
|
|
|
span.add(
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: newBadge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
|
|
|
|
backgroundColor: const Color(0xFF00AD03),
|
2021-12-31 20:39:58 -05:00
|
|
|
),
|
2022-01-02 03:45:00 -05:00
|
|
|
);
|
|
|
|
|
span.add(const TextSpan(text: ' '));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-12-31 21:03:19 -05:00
|
|
|
|
2022-01-02 03:45:00 -05:00
|
|
|
// Add custom FFZ vip badge if it exists
|
2022-01-12 09:29:31 -05:00
|
|
|
if (badgeInfo.name == 'VIP' && ffzRoomInfo?.vipBadge != null) {
|
2022-01-02 03:45:00 -05:00
|
|
|
badgeUrl = 'https:' + (ffzRoomInfo!.vipBadge?.url4x ?? ffzRoomInfo.vipBadge?.url2x ?? ffzRoomInfo.vipBadge!.url1x);
|
|
|
|
|
}
|
2021-12-31 21:03:19 -05:00
|
|
|
|
2022-01-12 13:55:49 -05:00
|
|
|
final newBadge = Badge(
|
|
|
|
|
name: badgeInfo.name,
|
|
|
|
|
url: badgeUrl,
|
|
|
|
|
type: BadgeType.twitch,
|
|
|
|
|
);
|
|
|
|
|
|
2021-12-31 20:39:58 -05:00
|
|
|
span.add(
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: newBadge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
2021-12-31 20:39:58 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
span.add(const TextSpan(text: ' '));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-30 23:00:03 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-02 03:45:00 -05:00
|
|
|
// Add FFZ badges to span
|
|
|
|
|
if (ffzUserBadges != null) {
|
|
|
|
|
for (final badge in ffzUserBadges) {
|
2022-01-16 23:48:34 -05:00
|
|
|
final color = Color(int.parse(badge.color!.replaceFirst('#', '0xFF')));
|
2022-01-16 23:41:19 -05:00
|
|
|
|
2022-01-12 09:29:31 -05:00
|
|
|
if (badge.name == 'Bot') {
|
2022-01-02 03:45:00 -05:00
|
|
|
if (!skipBot) {
|
|
|
|
|
span.insert(
|
|
|
|
|
0,
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: badge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
2022-01-16 23:41:19 -05:00
|
|
|
backgroundColor: color,
|
2022-01-02 03:45:00 -05:00
|
|
|
),
|
|
|
|
|
);
|
2022-01-02 17:53:25 -05:00
|
|
|
span.add(const TextSpan(text: ' '));
|
2021-12-31 20:39:58 -05:00
|
|
|
}
|
2022-01-02 03:45:00 -05:00
|
|
|
} else {
|
2021-12-15 23:54:06 -05:00
|
|
|
span.add(
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: badge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
2022-01-16 23:41:19 -05:00
|
|
|
backgroundColor: color,
|
2021-12-15 23:54:06 -05:00
|
|
|
),
|
|
|
|
|
);
|
2022-01-02 17:53:25 -05:00
|
|
|
span.add(const TextSpan(text: ' '));
|
2021-12-15 23:54:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 00:58:06 -05:00
|
|
|
// Add BTTV badges to span
|
2022-01-07 12:42:15 -05:00
|
|
|
final userBTTVBadge = bttvUserToBadge[tags['user-id']];
|
2022-01-01 00:58:06 -05:00
|
|
|
if (userBTTVBadge != null) {
|
|
|
|
|
span.add(
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: userBTTVBadge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
|
|
|
|
isSvg: true,
|
2022-01-01 00:58:06 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
span.add(const TextSpan(text: ' '));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 23:38:50 -05:00
|
|
|
// Add 7TV badges to end of badges span
|
2022-01-07 12:42:15 -05:00
|
|
|
final user7TVBadges = sevenTVUserToBadges[tags['user-id']];
|
2021-12-31 23:38:50 -05:00
|
|
|
if (user7TVBadges != null) {
|
|
|
|
|
for (final badge in user7TVBadges) {
|
|
|
|
|
span.add(
|
2022-01-12 13:55:49 -05:00
|
|
|
_createBadgeSpan(
|
|
|
|
|
badge: badge,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: badgeHeight,
|
2021-12-31 23:38:50 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
span.add(const TextSpan(text: ' '));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-16 23:48:34 -05:00
|
|
|
var color = Color(int.parse((tags['color'] ?? '#868686').replaceFirst('#', '0xFF')));
|
2022-01-06 09:32:39 -05:00
|
|
|
|
|
|
|
|
if (useReadableColors) {
|
|
|
|
|
final hsl = HSLColor.fromColor(color);
|
2022-01-11 00:45:43 -05:00
|
|
|
if (isLightTheme == true) {
|
|
|
|
|
if (hsl.lightness >= 0.5) color = hsl.withLightness(hsl.lightness + ((0 - hsl.lightness) * 0.5)).toColor();
|
|
|
|
|
} else {
|
|
|
|
|
if (hsl.lightness <= 0.5) color = hsl.withLightness(hsl.lightness + ((1 - hsl.lightness) * 0.5)).toColor();
|
|
|
|
|
}
|
2022-01-06 09:32:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Printing template for debugging purposes.
|
|
|
|
|
// debugPrint('OLD - NAME: ${tags['display-name']!}, HUE: ${hsl.hue}, SATURATION: ${hsl.saturation}, LIGHNTESS: ${hsl.lightness}');
|
|
|
|
|
// debugPrint('NEW - NAME: ${tags['display-name']!}, HUE: ${hsl.hue}, SATURATION: ${hsl.saturation}, LIGHNTESS: ${hsl.lightness}');
|
|
|
|
|
|
2021-12-15 23:54:06 -05:00
|
|
|
span.add(
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: tags['display-name']!,
|
|
|
|
|
style: TextStyle(
|
2022-01-06 09:32:39 -05:00
|
|
|
color: color,
|
2021-12-15 23:54:06 -05:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add the colon separator between the username and their message to the span.
|
2022-01-16 12:39:20 -05:00
|
|
|
if (action == false) span.add(const TextSpan(text: ':'));
|
2021-12-15 23:54:06 -05:00
|
|
|
|
2021-12-17 20:43:03 -05:00
|
|
|
// Italicize the text it was called with an IRC Action i.e., "/me".
|
2022-01-03 00:43:13 -05:00
|
|
|
final textStyle = action == true ? const TextStyle(fontStyle: FontStyle.italic) : style;
|
2021-12-17 20:43:03 -05:00
|
|
|
|
2022-01-06 23:06:25 -05:00
|
|
|
if (!showMessage) {
|
2021-12-15 23:54:06 -05:00
|
|
|
span.add(const TextSpan(text: ' <message deleted>'));
|
|
|
|
|
} else {
|
|
|
|
|
// Add the message and any emotes to the span.
|
2022-01-12 12:20:02 -05:00
|
|
|
final words = split;
|
|
|
|
|
if (words != null) {
|
2022-01-06 23:06:25 -05:00
|
|
|
if (useZeroWidth) {
|
2022-01-16 14:19:08 -05:00
|
|
|
// Keep a local span which will be reversed and added to the final span.
|
2021-12-15 23:54:06 -05:00
|
|
|
final localSpan = <InlineSpan>[];
|
|
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// Iterate through the words in reverse-order.
|
|
|
|
|
// Index starts at the last word in the message.
|
2021-12-15 23:54:06 -05:00
|
|
|
var index = words.length - 1;
|
2022-01-16 14:19:08 -05:00
|
|
|
|
|
|
|
|
// Terminate after the first word in the message reached.
|
2021-12-15 23:54:06 -05:00
|
|
|
while (index != -1) {
|
2022-01-16 14:19:08 -05:00
|
|
|
// Check if current word is a valid emote.
|
2021-12-15 23:54:06 -05:00
|
|
|
final word = words[index];
|
2022-01-12 12:20:02 -05:00
|
|
|
final emote = emoteToObject[word] ?? localEmotes?[word];
|
2021-12-15 23:54:06 -05:00
|
|
|
|
|
|
|
|
if (emote != null) {
|
2022-01-16 14:19:08 -05:00
|
|
|
// If the emote is zero-width and not the first word, process the stack.
|
2021-12-15 23:54:06 -05:00
|
|
|
if (emote.zeroWidth && index != 0) {
|
|
|
|
|
final emoteStack = <Emote>[];
|
|
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// Handle stacking consecutive zero-width emotes.
|
2022-01-01 23:50:02 -05:00
|
|
|
Emote? nextEmote = emote;
|
2021-12-15 23:54:06 -05:00
|
|
|
while (nextEmote != null && nextEmote.zeroWidth && index != 0) {
|
|
|
|
|
emoteStack.add(nextEmote);
|
|
|
|
|
index--;
|
2022-01-12 12:20:02 -05:00
|
|
|
nextEmote = emoteToObject[words[index]] ?? localEmotes?[words[index]];
|
2021-12-15 23:54:06 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// If there's one more emote thats NOT zero-width, add it to the base of the stack.
|
2021-12-15 23:54:06 -05:00
|
|
|
if (nextEmote != null) emoteStack.add(nextEmote);
|
|
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// Check if the next word is an emoji to be added to the stack.
|
|
|
|
|
final nextWordIsEmoji = regexEmoji.hasMatch(words[index]);
|
|
|
|
|
|
|
|
|
|
// Create the stack of emotes with the base emoji if there is one.
|
|
|
|
|
// Will be used as the children of the Stack widget.
|
|
|
|
|
final children = [
|
|
|
|
|
if (nextWordIsEmoji)
|
|
|
|
|
Text(
|
|
|
|
|
words[index],
|
2022-03-20 01:08:14 -04:00
|
|
|
style: textStyle?.copyWith(fontSize: emoteHeight - 5),
|
2022-01-16 14:19:08 -05:00
|
|
|
),
|
|
|
|
|
...emoteStack.reversed.map(
|
|
|
|
|
(emote) => CachedNetworkImage(
|
|
|
|
|
imageUrl: emote.url,
|
|
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: emoteHeight,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
];
|
2021-12-31 22:31:09 -05:00
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// Create the message for the tooltip
|
|
|
|
|
final message = emoteStack.reversed.map((emote) => emote.name).join(', ');
|
|
|
|
|
final tooltip = nextWordIsEmoji ? words[index] + ', ' + message : message;
|
2021-12-15 23:54:06 -05:00
|
|
|
localSpan.add(
|
|
|
|
|
WidgetSpan(
|
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
|
child: Tooltip(
|
2022-01-16 14:19:08 -05:00
|
|
|
richMessage: WidgetSpan(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Stack(
|
2022-03-20 01:08:14 -04:00
|
|
|
alignment: AlignmentDirectional.center,
|
2022-01-16 14:19:08 -05:00
|
|
|
children: [
|
|
|
|
|
if (nextWordIsEmoji)
|
|
|
|
|
Text(
|
|
|
|
|
words[index],
|
2022-03-20 01:08:14 -04:00
|
|
|
style: textStyle?.copyWith(fontSize: 75),
|
2022-01-16 14:19:08 -05:00
|
|
|
),
|
|
|
|
|
...emoteStack.reversed.map(
|
|
|
|
|
(emote) => CachedNetworkImage(
|
|
|
|
|
imageUrl: emote.url,
|
|
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: 80,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 5.0),
|
|
|
|
|
Text(
|
|
|
|
|
tooltip,
|
|
|
|
|
style: const TextStyle(color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2021-12-15 23:54:06 -05:00
|
|
|
preferBelow: false,
|
|
|
|
|
child: Stack(
|
|
|
|
|
alignment: AlignmentDirectional.center,
|
2022-01-16 14:19:08 -05:00
|
|
|
children: children,
|
2021-12-15 23:54:06 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
2022-01-16 14:19:08 -05:00
|
|
|
// If the next word is neither an emote or emoji, add it as a text span.
|
2021-12-31 22:31:09 -05:00
|
|
|
if (nextEmote == null && !nextWordIsEmoji) {
|
2021-12-15 23:54:06 -05:00
|
|
|
localSpan.add(const TextSpan(text: ' '));
|
2022-01-03 00:43:13 -05:00
|
|
|
localSpan.add(_createTextSpan(text: words[index], style: textStyle));
|
2021-12-15 23:54:06 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
localSpan.add(
|
2022-01-02 03:45:00 -05:00
|
|
|
_createEmoteSpan(
|
2022-01-12 13:55:49 -05:00
|
|
|
emote: emote,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: emoteHeight,
|
2021-12-15 23:54:06 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-01-11 20:58:30 -05:00
|
|
|
if (regexEmoji.hasMatch(word)) {
|
2022-03-20 01:08:14 -04:00
|
|
|
localSpan.add(_createEmojiSpan(emoji: word, style: textStyle?.copyWith(fontSize: emoteHeight - 5)));
|
2022-01-11 20:58:30 -05:00
|
|
|
} else {
|
|
|
|
|
localSpan.add(_createTextSpan(text: word, style: textStyle));
|
|
|
|
|
}
|
2021-12-15 23:54:06 -05:00
|
|
|
}
|
|
|
|
|
localSpan.add(const TextSpan(text: ' '));
|
|
|
|
|
index--;
|
|
|
|
|
}
|
2022-01-16 14:19:08 -05:00
|
|
|
|
|
|
|
|
// Add the the local span reversed to the final span.
|
2021-12-15 23:54:06 -05:00
|
|
|
span.addAll(localSpan.reversed);
|
|
|
|
|
} else {
|
2022-01-16 14:19:08 -05:00
|
|
|
// Iterate through the words and add to the span based on word, emote, and emoji.
|
2021-12-15 23:54:06 -05:00
|
|
|
for (final word in words) {
|
2022-01-03 00:43:13 -05:00
|
|
|
span.add(const TextSpan(text: ' '));
|
2021-12-15 23:54:06 -05:00
|
|
|
|
2022-01-12 12:20:02 -05:00
|
|
|
final emote = emoteToObject[word] ?? localEmotes?[word];
|
2021-12-15 23:54:06 -05:00
|
|
|
if (emote != null) {
|
|
|
|
|
span.add(
|
2022-01-02 03:45:00 -05:00
|
|
|
_createEmoteSpan(
|
2022-01-12 13:55:49 -05:00
|
|
|
emote: emote,
|
2022-01-02 03:45:00 -05:00
|
|
|
height: emoteHeight,
|
2021-12-15 23:54:06 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2022-01-11 20:58:30 -05:00
|
|
|
if (regexEmoji.hasMatch(word)) {
|
2022-03-20 01:08:14 -04:00
|
|
|
span.add(_createEmojiSpan(emoji: word, style: textStyle?.copyWith(fontSize: emoteHeight - 5)));
|
2022-01-11 20:58:30 -05:00
|
|
|
} else {
|
|
|
|
|
span.add(_createTextSpan(text: word, style: textStyle));
|
|
|
|
|
}
|
2021-12-15 23:54:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return span;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 19:08:24 -05:00
|
|
|
static WidgetSpan _createEmojiSpan({
|
|
|
|
|
required String emoji,
|
|
|
|
|
TextStyle? style,
|
|
|
|
|
}) {
|
|
|
|
|
return WidgetSpan(
|
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
|
child: Text(
|
|
|
|
|
emoji,
|
|
|
|
|
style: style,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 13:55:49 -05:00
|
|
|
static Widget _createBadgeWidget({
|
|
|
|
|
required Badge badge,
|
2022-01-02 03:45:00 -05:00
|
|
|
required double height,
|
|
|
|
|
Color? backgroundColor,
|
|
|
|
|
bool? isSvg,
|
|
|
|
|
}) {
|
|
|
|
|
if (backgroundColor != null) {
|
2022-01-12 13:55:49 -05:00
|
|
|
return ColoredBox(
|
2022-01-02 03:45:00 -05:00
|
|
|
color: backgroundColor,
|
|
|
|
|
child: CachedNetworkImage(
|
2022-01-12 13:55:49 -05:00
|
|
|
imageUrl: badge.url,
|
2022-01-02 03:45:00 -05:00
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: height,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else if (isSvg == true) {
|
2022-01-12 13:55:49 -05:00
|
|
|
return SvgPicture.network(
|
|
|
|
|
badge.url,
|
2022-01-02 03:45:00 -05:00
|
|
|
placeholderBuilder: (context) => const SizedBox(),
|
|
|
|
|
height: height,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2022-01-12 13:55:49 -05:00
|
|
|
return CachedNetworkImage(
|
|
|
|
|
imageUrl: badge.url,
|
2022-01-02 03:45:00 -05:00
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: height,
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-01-12 13:55:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WidgetSpan _createBadgeSpan({
|
|
|
|
|
required Badge badge,
|
|
|
|
|
required double height,
|
|
|
|
|
Color? backgroundColor,
|
|
|
|
|
bool? isSvg,
|
|
|
|
|
}) {
|
|
|
|
|
return WidgetSpan(
|
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
|
child: Tooltip(
|
|
|
|
|
richMessage: WidgetSpan(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
_createBadgeWidget(
|
|
|
|
|
badge: badge,
|
|
|
|
|
height: 80,
|
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
|
isSvg: isSvg,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 5.0),
|
|
|
|
|
Text(
|
|
|
|
|
badge.name,
|
|
|
|
|
style: const TextStyle(color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
preferBelow: false,
|
|
|
|
|
child: _createBadgeWidget(
|
|
|
|
|
badge: badge,
|
|
|
|
|
height: height,
|
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
|
isSvg: isSvg,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WidgetSpan _createEmoteSpan({
|
|
|
|
|
required Emote emote,
|
|
|
|
|
required double height,
|
|
|
|
|
}) {
|
|
|
|
|
const emoteType = [
|
2022-02-03 21:43:59 -05:00
|
|
|
'Twitch (Bits Tier)',
|
|
|
|
|
'Twitch (Follower)',
|
|
|
|
|
'Twitch (Subscriber)',
|
2022-01-12 13:55:49 -05:00
|
|
|
'Twitch (Global)',
|
|
|
|
|
'Twitch (Unlocked)',
|
|
|
|
|
'Twitch (Channel)',
|
|
|
|
|
'FFZ (Global)',
|
|
|
|
|
'FFZ (Channel)',
|
|
|
|
|
'BTTV (Global)',
|
|
|
|
|
'BTTV (Channel)',
|
|
|
|
|
'BTTV (Shared)',
|
|
|
|
|
'7TV (Global)',
|
|
|
|
|
'7TV (Channel)',
|
|
|
|
|
];
|
2022-01-02 03:45:00 -05:00
|
|
|
|
|
|
|
|
return WidgetSpan(
|
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
|
child: Tooltip(
|
2022-01-12 13:55:49 -05:00
|
|
|
richMessage: WidgetSpan(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
CachedNetworkImage(
|
|
|
|
|
imageUrl: emote.url,
|
|
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: 80,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 5.0),
|
|
|
|
|
Text(
|
|
|
|
|
emote.name,
|
|
|
|
|
style: const TextStyle(color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
emoteType[emote.type.index],
|
|
|
|
|
style: const TextStyle(color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2022-01-02 03:45:00 -05:00
|
|
|
preferBelow: false,
|
2022-01-12 13:55:49 -05:00
|
|
|
child: CachedNetworkImage(
|
|
|
|
|
imageUrl: emote.url,
|
|
|
|
|
placeholder: (context, url) => const SizedBox(),
|
|
|
|
|
fadeInDuration: const Duration(seconds: 0),
|
|
|
|
|
height: height,
|
|
|
|
|
),
|
2022-01-02 03:45:00 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 13:55:49 -05:00
|
|
|
static TextSpan _createTextSpan({required String text, TextStyle? style}) {
|
2022-01-03 00:43:13 -05:00
|
|
|
if (text.startsWith('@')) {
|
|
|
|
|
return TextSpan(text: text, style: style?.copyWith(fontWeight: FontWeight.bold));
|
2022-01-06 11:37:40 -05:00
|
|
|
} else if (RegExp(r'https?:\/\/').hasMatch(text)) {
|
2022-01-05 15:11:37 -05:00
|
|
|
return TextSpan(
|
|
|
|
|
text: text,
|
|
|
|
|
style: style?.copyWith(color: Colors.blue),
|
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
|
..onTap = () async {
|
2022-01-06 11:37:40 -05:00
|
|
|
if (await canLaunch(text)) launch(text);
|
2022-01-05 15:11:37 -05:00
|
|
|
},
|
|
|
|
|
);
|
2022-01-03 00:43:13 -05:00
|
|
|
} else {
|
|
|
|
|
return TextSpan(text: text, style: style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 23:54:06 -05:00
|
|
|
/// Parses an IRC string and returns its corresponding [IRCMessage] object.
|
2022-01-05 07:23:19 -05:00
|
|
|
factory IRCMessage.fromString(String whole, {String? userLogin}) {
|
2021-12-15 23:54:06 -05:00
|
|
|
// We have three parts:
|
|
|
|
|
// 1. The tags of the IRC message.
|
|
|
|
|
// 2. The metadata (user, command, and channel).
|
|
|
|
|
// 3. The message itself.
|
|
|
|
|
|
|
|
|
|
// First, slice the message tags (1) and set aside the rest for later.
|
|
|
|
|
// Each part is separated by a space, so we'll start off by breaking off the tags and parsing them.
|
|
|
|
|
|
|
|
|
|
// Obtain the index to break off the tags.
|
|
|
|
|
final tagAndIrcMessageDivider = whole.indexOf(' ');
|
|
|
|
|
|
|
|
|
|
// Get the tags substring and escape characters.
|
|
|
|
|
// IRC messages escape spaces with \s.
|
|
|
|
|
final tags = whole.substring(1, tagAndIrcMessageDivider).replaceAll('\\s', ' ');
|
|
|
|
|
|
|
|
|
|
// Next, parse and map the tags.
|
|
|
|
|
final mappedTags = <String, String>{};
|
|
|
|
|
|
|
|
|
|
// Loop through each tag and store their key value pairs into the map.
|
|
|
|
|
for (final tag in tags.split(';')) {
|
|
|
|
|
// Skip if the tag has no value.
|
|
|
|
|
if (tag.endsWith('=')) continue;
|
|
|
|
|
|
|
|
|
|
final tagSplit = tag.split('=');
|
|
|
|
|
mappedTags[tagSplit[0]] = tagSplit[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now we'll parse the message itself.
|
|
|
|
|
// Obtain the entire substring after the tags and excluding the first : (colon)
|
|
|
|
|
final ircMessage = whole.substring(tagAndIrcMessageDivider + 2);
|
|
|
|
|
|
|
|
|
|
// Split each section of the message (part 2 and its subparts and part 3).
|
|
|
|
|
// Index 0 contains the username of sender (user) or tmi.twitch.tv depending on the command
|
|
|
|
|
// Index 1 is command type
|
|
|
|
|
// Index 2 is #channel name that we are currently connected to
|
|
|
|
|
// Index 3 and beyond is the :message (word by word) that is sent by the user or empty depending on the command
|
|
|
|
|
final splitMessage = ircMessage.split(' ');
|
|
|
|
|
|
|
|
|
|
// If the username exists, set it.
|
|
|
|
|
// tmi.twitch.tv means the message was sent by Twitch rather than a user, so will be irrelevant.
|
|
|
|
|
final String? user = splitMessage[0] == 'tmi.twitch.tv' ? null : splitMessage[0].substring(0, splitMessage[0].indexOf('!'));
|
|
|
|
|
|
|
|
|
|
// If there is an associated message, set it.
|
2021-12-17 20:43:03 -05:00
|
|
|
//
|
|
|
|
|
// Also remove any "INVALID/UNDEFINED" Unicode characters.
|
|
|
|
|
// Rendering this character on iOS shows a question mark inside a square.
|
|
|
|
|
// This character is used by some clients to bypass restrictions on repeating message.
|
2022-01-12 11:13:57 -05:00
|
|
|
var message = splitMessage.length > 3 ? splitMessage.sublist(3).join(' ').substring(1) : null;
|
2022-01-03 00:43:13 -05:00
|
|
|
|
2021-12-17 20:43:03 -05:00
|
|
|
// Now process any Twitch emotes contained in the message tags.
|
|
|
|
|
// The map containing emotes from the user's tags to their URL.
|
|
|
|
|
// This may include sub emotes that they can access but other users cannot.
|
|
|
|
|
final localEmotes = <String, Emote>{};
|
|
|
|
|
|
|
|
|
|
final emoteTags = mappedTags['emotes'];
|
|
|
|
|
if (emoteTags != null) {
|
|
|
|
|
// Emotes and their indices are separated by '/' so split them there.
|
|
|
|
|
final emotes = emoteTags.split('/');
|
|
|
|
|
|
|
|
|
|
for (final emoteIdAndPosition in emotes) {
|
|
|
|
|
final indexBetweenIdAndPositions = emoteIdAndPosition.indexOf(':');
|
|
|
|
|
final emoteId = emoteIdAndPosition.substring(0, indexBetweenIdAndPositions);
|
|
|
|
|
|
|
|
|
|
// Parse the range in order to extract the associated word.
|
|
|
|
|
// If there are more than one indices, use the first one.
|
|
|
|
|
// Else, use the one provided indices.
|
|
|
|
|
final String range;
|
|
|
|
|
if (emoteIdAndPosition.contains(',')) {
|
|
|
|
|
range = emoteIdAndPosition.substring(indexBetweenIdAndPositions + 1, emoteIdAndPosition.indexOf(','));
|
|
|
|
|
} else {
|
|
|
|
|
range = emoteIdAndPosition.substring(indexBetweenIdAndPositions + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extract the word associated with this emoteId by using the provided indices.
|
|
|
|
|
final indexSplit = range.split('-');
|
|
|
|
|
final startIndex = int.parse(indexSplit[0]);
|
|
|
|
|
final endIndex = int.parse(indexSplit[1]);
|
|
|
|
|
|
|
|
|
|
final emoteWord = message!.substring(startIndex, endIndex + 1);
|
|
|
|
|
|
|
|
|
|
// Store the emote word and its associated URL for later use.
|
|
|
|
|
localEmotes[emoteWord] = Emote(
|
|
|
|
|
name: emoteWord,
|
|
|
|
|
zeroWidth: false,
|
|
|
|
|
url: 'https://static-cdn.jtvnw.net/emoticons/v2/$emoteId/default/dark/3.0',
|
2022-02-03 21:43:59 -05:00
|
|
|
type: EmoteType.twitchSub,
|
2021-12-17 20:43:03 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-15 23:54:06 -05:00
|
|
|
|
2022-01-12 11:13:57 -05:00
|
|
|
var action = false;
|
|
|
|
|
var mention = false;
|
2022-01-12 12:20:02 -05:00
|
|
|
List<String>? split;
|
2022-01-12 11:13:57 -05:00
|
|
|
if (message != null) {
|
|
|
|
|
// Check if IRC actions like "/me" were called.
|
|
|
|
|
if (message.startsWith('\x01') && message.endsWith('\x01')) {
|
|
|
|
|
action = true;
|
|
|
|
|
message = message.substring(8, message.length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the message mentions the logged-in user
|
|
|
|
|
if (userLogin != null) mention = message.toLowerCase().contains(userLogin);
|
|
|
|
|
|
|
|
|
|
// Escape the message
|
|
|
|
|
message = message.split(' ').map((word) => word.replaceAll('\u{E0000}', '').trim()).where((element) => element != '').join(' ');
|
2022-01-12 12:20:02 -05:00
|
|
|
|
|
|
|
|
final emojiBuffer = StringBuffer();
|
|
|
|
|
final wordBuffer = StringBuffer();
|
|
|
|
|
split = <String>[];
|
|
|
|
|
|
|
|
|
|
for (final character in message.characters) {
|
|
|
|
|
if (regexEmoji.hasMatch(character)) {
|
|
|
|
|
if (wordBuffer.isNotEmpty) {
|
|
|
|
|
split.addAll(wordBuffer.toString().split(' '));
|
|
|
|
|
wordBuffer.clear();
|
|
|
|
|
}
|
|
|
|
|
emojiBuffer.write(character);
|
|
|
|
|
} else {
|
|
|
|
|
if (emojiBuffer.isNotEmpty) {
|
|
|
|
|
split.add(emojiBuffer.toString());
|
|
|
|
|
emojiBuffer.clear();
|
|
|
|
|
}
|
|
|
|
|
wordBuffer.write(character);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wordBuffer.isNotEmpty) split.addAll(wordBuffer.toString().split(' ').where((element) => element != ''));
|
|
|
|
|
if (emojiBuffer.isNotEmpty) split.add(emojiBuffer.toString());
|
2022-01-12 11:13:57 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-15 23:54:06 -05:00
|
|
|
// Check and parse the command.
|
|
|
|
|
// The majority of messages will be PRIVMSG, so check that first.
|
|
|
|
|
final Command messageCommand;
|
|
|
|
|
switch (splitMessage[1]) {
|
|
|
|
|
case 'PRIVMSG':
|
|
|
|
|
messageCommand = Command.privateMessage;
|
|
|
|
|
break;
|
|
|
|
|
case 'CLEARCHAT':
|
|
|
|
|
messageCommand = Command.clearChat;
|
|
|
|
|
break;
|
|
|
|
|
case 'CLEARMSG':
|
|
|
|
|
messageCommand = Command.clearMessage;
|
|
|
|
|
break;
|
|
|
|
|
case 'NOTICE':
|
|
|
|
|
messageCommand = Command.notice;
|
|
|
|
|
break;
|
|
|
|
|
case 'USERNOTICE':
|
|
|
|
|
messageCommand = Command.userNotice;
|
|
|
|
|
break;
|
|
|
|
|
case 'ROOMSTATE':
|
|
|
|
|
messageCommand = Command.roomState;
|
|
|
|
|
break;
|
|
|
|
|
case 'USERSTATE':
|
|
|
|
|
messageCommand = Command.userState;
|
|
|
|
|
break;
|
|
|
|
|
case 'GLOBALUSERSTATE':
|
|
|
|
|
messageCommand = Command.globalUserState;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
debugPrint('Unknown command: $splitMessage[1]');
|
|
|
|
|
messageCommand = Command.none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IRCMessage(
|
2022-01-12 16:03:37 -05:00
|
|
|
raw: whole,
|
2021-12-15 23:54:06 -05:00
|
|
|
command: messageCommand,
|
2022-01-12 12:20:02 -05:00
|
|
|
tags: mappedTags,
|
2021-12-15 23:54:06 -05:00
|
|
|
user: user,
|
2022-01-12 12:20:02 -05:00
|
|
|
localEmotes: localEmotes,
|
2021-12-15 23:54:06 -05:00
|
|
|
message: message,
|
2022-01-12 12:20:02 -05:00
|
|
|
split: split,
|
|
|
|
|
action: action,
|
2022-01-03 00:43:13 -05:00
|
|
|
mention: mention,
|
2021-12-15 23:54:06 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory IRCMessage.createNotice({required String message}) => IRCMessage(
|
2022-01-12 16:03:37 -05:00
|
|
|
raw: '',
|
2021-12-15 23:54:06 -05:00
|
|
|
tags: {},
|
|
|
|
|
command: Command.notice,
|
|
|
|
|
message: message,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The object representation of the IRC ROOMSTATE message.
|
|
|
|
|
class ROOMSTATE {
|
2021-12-27 21:13:46 -05:00
|
|
|
final String emoteOnly;
|
2021-12-15 23:54:06 -05:00
|
|
|
final String followersOnly;
|
2021-12-27 21:13:46 -05:00
|
|
|
final String r9k;
|
2021-12-15 23:54:06 -05:00
|
|
|
final String slowMode;
|
2021-12-27 21:13:46 -05:00
|
|
|
final String subMode;
|
2021-12-15 23:54:06 -05:00
|
|
|
|
|
|
|
|
const ROOMSTATE({
|
2021-12-27 21:13:46 -05:00
|
|
|
this.emoteOnly = '0',
|
2021-12-15 23:54:06 -05:00
|
|
|
this.followersOnly = '-1',
|
2021-12-27 21:13:46 -05:00
|
|
|
this.r9k = '0',
|
2021-12-15 23:54:06 -05:00
|
|
|
this.slowMode = '0',
|
2021-12-27 21:13:46 -05:00
|
|
|
this.subMode = '0',
|
2021-12-15 23:54:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/// Create a new copy with the parameters from the provided [IRCMessage]
|
2021-12-17 20:43:03 -05:00
|
|
|
ROOMSTATE fromIRCMessage(IRCMessage ircMessage) => ROOMSTATE(
|
2021-12-27 21:13:46 -05:00
|
|
|
emoteOnly: ircMessage.tags['emote-only'] ?? emoteOnly,
|
2021-12-15 23:54:06 -05:00
|
|
|
followersOnly: ircMessage.tags['followers-only'] ?? followersOnly,
|
2021-12-27 21:13:46 -05:00
|
|
|
r9k: ircMessage.tags['r9k'] ?? r9k,
|
2021-12-15 23:54:06 -05:00
|
|
|
slowMode: ircMessage.tags['slow'] ?? slowMode,
|
2021-12-27 21:13:46 -05:00
|
|
|
subMode: ircMessage.tags['subs-only'] ?? subMode,
|
2021-12-15 23:54:06 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class USERSTATE {
|
|
|
|
|
final String? raw;
|
|
|
|
|
final String color;
|
|
|
|
|
final String displayName;
|
|
|
|
|
final bool mod;
|
|
|
|
|
final bool subscriber;
|
|
|
|
|
|
|
|
|
|
const USERSTATE({
|
|
|
|
|
this.raw,
|
|
|
|
|
this.color = '',
|
|
|
|
|
this.displayName = '',
|
|
|
|
|
this.mod = false,
|
|
|
|
|
this.subscriber = false,
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-17 20:43:03 -05:00
|
|
|
USERSTATE fromIRCMessage(IRCMessage ircMessage) => USERSTATE(
|
2022-01-12 16:03:37 -05:00
|
|
|
raw: ircMessage.raw,
|
2021-12-15 23:54:06 -05:00
|
|
|
color: ircMessage.tags['color'] ?? color,
|
|
|
|
|
displayName: ircMessage.tags['display-name'] ?? displayName,
|
|
|
|
|
mod: ircMessage.tags['mod'] == '0' ? false : true,
|
|
|
|
|
subscriber: ircMessage.tags['subscriber'] == '0' ? false : true,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-12-16 00:06:28 -05:00
|
|
|
|
|
|
|
|
/// The possible types of Twitch IRC commands.
|
|
|
|
|
enum Command {
|
|
|
|
|
privateMessage,
|
|
|
|
|
clearChat,
|
|
|
|
|
clearMessage,
|
|
|
|
|
notice,
|
|
|
|
|
userNotice,
|
|
|
|
|
roomState,
|
|
|
|
|
userState,
|
|
|
|
|
globalUserState,
|
|
|
|
|
none,
|
|
|
|
|
}
|
2022-01-11 20:58:30 -05:00
|
|
|
|
|
|
|
|
// Regex from dart_emoji package; used for emoji compatibility with zero-width
|
|
|
|
|
final regexEmoji = RegExp(
|
|
|
|
|
r'[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}'
|
|
|
|
|
r'\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}'
|
|
|
|
|
r'-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}'
|
|
|
|
|
r'\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}'
|
|
|
|
|
r'-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}'
|
|
|
|
|
r'\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}'
|
|
|
|
|
r'-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}'
|
|
|
|
|
r'\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}'
|
|
|
|
|
r'-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}\u{200d}]+',
|
|
|
|
|
unicode: true,
|
|
|
|
|
);
|