Example #1
0
        public event EventHandler <TasSayEventArgs> Said = delegate { }; // this is fired when any kind of say message is recieved


        /// <summary>
        ///     Say something through chat system
        /// </summary>
        /// <param Name="place">Pick user (private message) channel or battle</param>
        /// <param Name="channel">Channel or User Name</param>
        /// <param Name="inputtext">chat text</param>
        /// <param Name="isEmote">is message emote? (channel or battle only)</param>
        /// <param Name="linePrefix">text to be inserted in front of each line (example: "!pm xyz")</param>
        public async Task Say(SayPlace place, string channel, string inputtext, bool isEmote, bool isRing = false)
        {
            if (string.IsNullOrEmpty(inputtext))
            {
                return;
            }
            var lines = inputtext.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var text in lines)
            {
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }

                var args = new SayingEventArgs(place, channel, text, isEmote);
                Saying(this, args);
                if (args.Cancel)
                {
                    continue;
                }

                if ((args.SayPlace == SayPlace.Channel) && !JoinedChannels.ContainsKey(args.Channel))
                {
                    await JoinChannel(args.Channel);
                }

                var say = new Say()
                {
                    Target = args.Channel, Place = args.SayPlace, Text = args.Text, IsEmote = args.IsEmote, Ring = isRing
                };

                await SendCommand(say);
            }
        }
 void client_Saying(object sender, SayingEventArgs e)
 {
     if (e.Text.Length > 0 && e.Text[0] == '/')
     {
         if (e.Text.StartsWith("/me"))
         {
             e.Text = e.Text.Substring(4);
             e.IsEmote = true;
         }
         else
         {
             e.Cancel = true;
             var words = e.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
             if ((words[0] == "/j" || words[0] == "/join" || words[0] == "/channel") && words.Length > 1)
             {
                 if (words.Length == 2) Program.TasClient.JoinChannel(words[1].Replace("#", String.Empty));
                 else
                 {
                     Program.TasClient.JoinChannel(words[1].Replace("#", String.Empty), words[2]);
                     Program.AutoJoinManager.AddPassword(words[1], words[2]);
                 }
             }
             else if (words[0] == "/p" || words[0] == "/part" || words[0] == "/l" || words[0] == "/leave") Program.TasClient.LeaveChannel(e.Channel);
             else if ((words[0] == "/pm" || words[0] == "/msg" || words[0] == "/message" || words[0] == "/w") && words.Length > 2) Program.TasClient.Say(SayPlace.User, words[1], ZkData.Utils.Glue(words, 2), false);
             else if (words[0] == "/disconnect") Program.TasClient.RequestDisconnect();
             
             else if (words[0] == "/raw") Program.TasClient.SendRaw(ZkData.Utils.Glue(words, 1));
             //else if (words[0] == "/help") Program.MainWindow.navigationControl.Path = "help";
             else MainWindow.Instance.NotifyUser("server", "Command not recognized");
         }
     }
 }