-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.go
73 lines (64 loc) · 2.63 KB
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"strings"
)
const help = "🛡️ <b>Guardian Help Page</b> 🛡️:<br/>" +
"<code>!gd <<option>> <<args>></code><br/><br>" +
"<b>Options</b>:<br/>" +
"<code>url</code>: <i>Handle URLs in messages</i>"
const urlHelp = "🛡️ <b>Guardian Help Page [url]</b> 🛡️:<br/>" +
"<code>!gd url <<args>></code><br/><br/>" +
"<b>Arguments</b>:<br/>" +
"<code>block <<domain>></code>: <i>Block domain in messages</i><br/>" +
"<code>unblock <<domain>></code>: <i>Unblock domain in messages</i><br/>" +
"<code>list</code>: <i>List blocked domains in messages</i>"
const mimeHelp = "🛡️ <b>Guardian Help Page [mime]</b> 🛡️:<br/>" +
"<code>!gd mime <<args>></code><br/><br/>" +
"<b>Arguments</b>:<br/>" +
"<code>block <<mimetype>></code>: <i>Block MIME type in messages</i><br/>" +
"<code>unblock <<mimetype>></code>: <i>Unblock MIME type in messages</i><br/>" +
"<code>list</code>: <i>List blocked MIME type in messages</i>"
func getRawMessage(source string) string {
source = strings.ReplaceAll(source, "<b>", "")
source = strings.ReplaceAll(source, "</b>", "")
source = strings.ReplaceAll(source, "<i>", "")
source = strings.ReplaceAll(source, "</i><br/>", "; ")
source = strings.ReplaceAll(source, "</i>", " ")
source = strings.ReplaceAll(source, "<br/><br/>", ". ")
source = strings.ReplaceAll(source, "<br/>", " ")
source = strings.ReplaceAll(source, "<code>", "")
source = strings.ReplaceAll(source, "</code>", "")
source = strings.ReplaceAll(source, "<<", "<")
source = strings.ReplaceAll(source, ">>", ">")
return source
}
func getFormmatedMessage(source string) string {
source = strings.ReplaceAll(source, "<<", "<")
source = strings.ReplaceAll(source, ">>", ">")
return source
}
func sendHtmlMessage(client *mautrix.Client, ctx context.Context, mngtRoomId id.RoomID, message string) {
contentJson := &event.MessageEventContent{
MsgType: event.MsgNotice,
Format: event.FormatHTML,
Body: getRawMessage(message),
FormattedBody: getFormmatedMessage(message),
}
_, err := client.SendMessageEvent(ctx, mngtRoomId, event.EventMessage, contentJson)
if err != nil {
return
}
}
func ShowHelp(client *mautrix.Client, ctx context.Context, mngtRoomId id.RoomID) {
sendHtmlMessage(client, ctx, mngtRoomId, help)
}
func ShowUrlHelp(client *mautrix.Client, ctx context.Context, mngtRoomId id.RoomID) {
sendHtmlMessage(client, ctx, mngtRoomId, urlHelp)
}
func ShowMimeHelp(client *mautrix.Client, ctx context.Context, mngtRoomId id.RoomID) {
sendHtmlMessage(client, ctx, mngtRoomId, mimeHelp)
}