-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChatController.cs
109 lines (94 loc) · 3.38 KB
/
ChatController.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
using UnityEngine.UI;
///<Summary>A controller for a button that will convert the product of an InputField to a ChatMessage event.</Summary>
public class ChatController : UdonSharpBehaviour
{
///<Summary>The text input field for this controller.</Summary>
public InputField input;
///<Summary>The receiver we want to handle chat events.</Summary>
public EventReceiver receiver;
public string[] badWords;
private int maxMessageLength;
public void Start()
{
maxMessageLength = 50;
}
///<Summary>Send a ChatMessage using the product of an InputField.</Summary>
public void SendMessage()
{
if (input.text == "" || input.text == null)
{
return;
}
if (input.text.Length > maxMessageLength)
{
input.text = input.text.Substring(0, maxMessageLength);
}
string message = input.text;
if (badWordsFound(message) == false)
{
receiver.SendEvent("ChatMessage", message.Replace(",", "|"));
}
input.text = null;
}
public bool badWordsFound(string input)
{
bool found = false;
string[] inputs = input.Replace("1", "i")
.Replace("!", "i")
.Replace("3", "e")
.Replace("4", "a")
.Replace("@", "a")
.Replace("5", "s")
.Replace("7", "t")
.Replace("0", "o")
.Replace("9", "g")
.Replace("\"", "")
.Replace("£", "e")
.Replace("$", "s")
.Replace("€", "e")
.Replace("%", "")
.Replace("^", "")
.Replace("*", "")
.Replace("(", "")
.Replace(")", "")
.Replace("-", "")
.Replace("_", "")
.Replace("=", "")
.Replace("+", "")
.Replace("{", "")
.Replace("]", "")
.Replace("}", "")
.Replace(";", "")
.Replace("'", "")
.Replace("#", "")
.Replace("~", "")
.Replace("\\", "")
.Replace(",", "")
.Replace("?", "")
.Replace("/", "")
.ToLower()
.Split(' ');
for (int inputsIndex = 0; inputsIndex < inputs.Length; inputsIndex++)
{
input = inputs[inputsIndex];
for (int badWordsIndex = 0; badWordsIndex < badWords.Length; badWordsIndex++)
{
if (input.Contains(badWords[badWordsIndex]))
{
found = true;
break;
}
}
if (found)
{
break;
}
}
return found;
}
}