Example #1
0
 static void UserCommands(string userName, string message, IrcClient irc)
 {
     if (message.StartsWith("!hola"))
     {
         irc.SendPublicChatMessage("Mundo!");
     }
     if (message.StartsWith("!commands"))
     {
         List <string> Commands = new List <string>();
         foreach (CustomCommands command in CommandsList)
         {
             Commands.Add(command.CommandName);
         }
         string finalmsg = "The current commands are:";
         for (var i = 0; i < Commands.Count; i++)
         {
             finalmsg += " ";
             if (i == Commands.Count - 1)
             {
                 finalmsg += Commands[i];
             }
             else
             {
                 finalmsg += Commands[i];
                 finalmsg += ",";
             }
         }
         irc.SendPublicChatMessage(finalmsg);
     }
     foreach (CustomCommands command in UserCommandsList)
     {
         if (message.StartsWith(command.CommandName))
         {
             string finalmsg = command.CommandResponse;
             if (finalmsg.Contains("$USER"))
             {
                 finalmsg = finalmsg.Replace("$USER", userName);
                 Console.WriteLine(userName);
             }
             if (finalmsg.Contains("$COUNTER"))
             {
                 finalmsg         = finalmsg.Replace("$COUNTER", (command.Counter + 1).ToString());
                 command.Counter += 1;
                 CustomCommands.SaveCommands(CommandsList, CommandLocation);
             }
             Console.WriteLine(finalmsg);
             irc.SendPublicChatMessage(finalmsg);
             break;
         }
     }
 }
Example #2
0
 static async Task ModeratorCommands(string userName, string message, IrcClient irc)
 {
     if (message.StartsWith("!hello"))
     {
         irc.SendPublicChatMessage("World!");
     }
     if (message.StartsWith("!addcom"))
     {
         var fmtstring       = message.Substring(8);
         var FirstSpaceIndex = fmtstring.IndexOf(' ');
         var FirstString     = fmtstring.Substring(0, FirstSpaceIndex);
         foreach (CustomCommands com in CommandsList)
         {
             if (FirstString == com.CommandName)
             {
                 irc.SendPublicChatMessage("That command already exists. Try again");
                 goto End; // Ends the if statement if the command already exists.
             }
         }
         var            SecondString = fmtstring.Substring(FirstSpaceIndex + 1);
         CustomCommands command      = new CustomCommands();
         command.CommandName     = FirstString;
         command.CommandResponse = SecondString;
         command.IsModCommand    = false;
         CommandsList.Add(command);
         CustomCommands.SaveCommands(CommandsList, CommandLocation);
         irc.SendPublicChatMessage("Command added!");
         End :;
     }
     if (message.StartsWith("!delcom"))
     {
         var fmtstring    = message.Substring(8);
         var foundCommand = false;
         foreach (CustomCommands command in CommandsList)
         {
             if (command.CommandName == fmtstring)
             {
                 foundCommand = true;
                 CommandsList.Remove(command);
                 CustomCommands.SaveCommands(CommandsList, CommandLocation);
                 irc.SendPublicChatMessage("Command Removed!");
                 break;
             }
         }
         if (!foundCommand)
         {
             irc.SendPublicChatMessage("No command with that name exists");
         }
     }
     if (message.StartsWith("!editcom"))
     {
         var fmtstring       = message.Substring(9);
         var FirstSpaceIndex = fmtstring.IndexOf(' ');
         var FirstString     = fmtstring.Substring(0, FirstSpaceIndex);
         var foundCommand    = false;
         foreach (CustomCommands com in CommandsList)
         {
             if (FirstString == com.CommandName)
             {
                 var SecondString = fmtstring.Substring(FirstSpaceIndex + 1);
                 com.CommandResponse = SecondString;
                 CustomCommands.SaveCommands(CommandsList, CommandLocation);
                 foundCommand = true;
                 irc.SendPublicChatMessage("Command Edited!");
                 break;
             }
         }
         if (!foundCommand)
         {
             irc.SendPublicChatMessage("No command with that name exists");
         }
     }
 }