Пример #1
0
        private void ChatRoom_OnChatEvent(object sender, ChatEventArgs e)
        {
            if (disposed)
                return;

            if (e.ParsedJson["event"] != "add")
                return;
            if (!e.ParsedJson["body"].StartsWith(Prefix, StringComparison.Ordinal))
                return;
            string commandText = e.ParsedJson["body"].Remove(0, Prefix.Length);
            string[] commandWithArgs = commandText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (commandWithArgs.Length == 0)
                return;
            string command = commandWithArgs[0].ToUpperInvariant();
            string[] args = commandWithArgs.Skip(1).ToArray();
            CommandOutput output = null;
            if (Commands.ContainsKey(command))
            {
                output = Commands[command](args);
            }
            else if (OwnerCommands.ContainsKey(command))
            {
                if (Owners.Contains(e.ParsedJson["user"]))
                {
                    output = OwnerCommands[command](args);
                }
                else
                {
                    output = new CommandOutput("You don't have the privilege to execute this command.", true);
                }
            }
            else
            {
                output = new CommandOutput("Command not found.", true);
            }
            string s = string.Empty;
            if (output.Ping)
            {
                s = string.Format(CultureInfo.InvariantCulture, Properties.Resources.messageFormat, e.ParsedJson["user"], output.Output);
            }
            else
            {
                s = output.Output;
            }
            ChatRoom.Send(s);
        }
Пример #2
0
 protected void MessageReceived(object sender, MessageReceivedEventArgs e)
 {
     if (disposed || e == null)
         return;
     string json = e.Message;
     Dictionary<string, string> parsedJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
     ChatEventArgs cea = new ChatEventArgs(json, parsedJson);
     if (chatEvent != null)
     {
         chatEvent(this, cea);
     }
 }
Пример #3
0
 private static void ChatRoom_OnChatEvent(object sender, ChatEventArgs e)
 {
     // for logging
     Console.WriteLine(e.Json);
 }