Skip to content

Commit edcfc83

Browse files
committed
Improve nickname pooping and fix metrics
1 parent 68e5155 commit edcfc83

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

lib/src/modules/metrics.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DynamicMetric extends Metric {
6565
final ContextValueCallback extractValue;
6666

6767
DynamicMetric(super.objectId, super.name, this.extractValue, {super.unit, super.icon, super.isDiagnostic = false})
68-
: super(stateClass: 'measurement', deviceClass: 'data_size');
68+
: super(stateClass: 'measurement');
6969
}
7070

7171
class DiagnosticMetric extends Metric {
@@ -86,7 +86,7 @@ class BotInfoMetric extends Metric {
8686
final ExtractValueCallback extractValue;
8787

8888
BotInfoMetric(super.objectId, super.name, this.extractValue, {super.unit, super.icon, super.isDiagnostic = false})
89-
: super(stateClass: 'measurement', deviceClass: 'data_size');
89+
: super(stateClass: 'measurement');
9090
}
9191

9292
final List<DiagnosticMetric> oneTimeMetrics = [
@@ -194,18 +194,18 @@ class MetricsModule implements RequiresInitialization {
194194
return;
195195
}
196196

197+
Injector.appInstance.get<NyxxGateway>().onMessageCreate.listen((e) => dynamicMetricContext.messages++);
198+
Injector.appInstance.get<NyxxGateway>().onGuildMemberAdd.listen((e) => dynamicMetricContext.joins++);
199+
Injector.appInstance.get<NyxxGateway>().onGuildMemberRemove.listen((e) => dynamicMetricContext.removals++);
200+
Injector.appInstance.get<NyxxGateway>().onInteractionCreate.listen((e) => dynamicMetricContext.interactions++);
201+
Injector.appInstance.get<NyxxGateway>().onEvent.listen((e) => dynamicMetricContext.events++);
202+
197203
client = MqttServerClient(metricsMqttPath, deviceName, maxConnectionAttempts: 30);
198204
client.onConnected = _onConnected;
199205
client.onAutoReconnected = _onAutoReconnected;
200206
client.onDisconnected = _onDisconnected;
201207

202208
_connect();
203-
204-
Injector.appInstance.get<NyxxGateway>().onMessageCreate.listen((e) => dynamicMetricContext.messages++);
205-
Injector.appInstance.get<NyxxGateway>().onGuildMemberAdd.listen((e) => dynamicMetricContext.joins++);
206-
Injector.appInstance.get<NyxxGateway>().onGuildMemberRemove.listen((e) => dynamicMetricContext.removals++);
207-
Injector.appInstance.get<NyxxGateway>().onInteractionCreate.listen((e) => dynamicMetricContext.interactions++);
208-
Injector.appInstance.get<NyxxGateway>().onEvent.listen((e) => dynamicMetricContext.events++);
209209
}
210210

211211
Future<void> _connect() async {

lib/src/modules/poop_name.dart

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,38 @@ import 'package:running_on_dart/src/init.dart';
77

88
const poopEmoji = "💩";
99
const poopCharacters = [
10+
'(',
11+
')',
12+
'-',
13+
'+',
14+
'=',
15+
'_',
16+
']',
17+
'[',
18+
'\\',
19+
'|',
20+
';',
21+
"'",
22+
',',
23+
'.',
24+
'<',
25+
'>',
26+
'/',
27+
'?',
1028
'!',
11-
'#',
1229
'@',
13-
'^',
30+
'#',
31+
r'$',
1432
'%',
33+
'^',
1534
'&',
16-
'-',
1735
'*',
18-
'.'
19-
'+',
20-
"'",
2136
];
22-
final poopRegexp = RegExp("[${poopCharacters.join()}]");
37+
38+
final poopRegexp = RegExp("[${poopCharacters.map((c) => RegExp.escape(c)).join()}]");
39+
final weirdCharsRegexp = RegExp(
40+
r'[\u200B\u200C\u200D\u2060\uFEFF\u180E\u202A-\u202E\u2066-\u2069\u00AD\u061C\uFFF9-\uFFFB\uFFFD]|[\x00-\x1F\x7F-\x9F]',
41+
);
2342

2443
class PoopNameModule implements RequiresInitialization {
2544
final NyxxGateway _client = Injector.appInstance.get();
@@ -52,7 +71,7 @@ class PoopNameModule implements RequiresInitialization {
5271
return (true, memberName);
5372
}
5473

55-
bool _shouldPoopName(String name) => name.startsWith(poopRegexp);
74+
bool _shouldPoopName(String name) => name.startsWith(poopRegexp) || weirdCharsRegexp.hasMatch(name);
5675

5776
Future<void> _updateMemberWithPoopEmoji(Member member) =>
5877
member.update(MemberUpdateBuilder(nick: poopEmoji), auditLogReason: 'ROD PoopNameModule moderation');

0 commit comments

Comments
 (0)