public void Execute(ChatMessage msg, string[] parameters) { if (parameters.Length == 0) { ChannelChat.Send(usage); return; } if (parameters.Length == 2 && parameters[0].ToLower() == "del") { string CommandName = parameters[1].ToLower(); var command = Database.GetCustomCommand(CommandName); if (command == null) { ChannelChat.Send("Command not found"); return; } Database.DeleteCustomCommand(command); ChannelChat.Send($"Deleted Command {command.CmdName}"); return; } if (!(parameters.Length >= 3)) { ChannelChat.Send(usage); return; } string CName = parameters[1].ToLower(); string resp = string.Join(" ", parameters.Skip(2)); if (CName.StartsWith("/") || CName.StartsWith(".") || resp.StartsWith("/") || resp.StartsWith(".")) { ChannelChat.Send("Command names or responses cannot start with . or /"); return; } if (parameters[0].ToLower() == "add") { if (CommandHandler.Commands.FirstOrDefault(x => x.Command.ToLower() == CName) != null) { ChannelChat.Send($"Command {CName} already exist"); return; } Database.AddOrUpdateCustomCommand(new Data.CustomCommand { CmdName = CName, Reponse = resp }); ChannelChat.Send($"Added Command {CName}"); } else if (parameters[0].ToLower() == "edit") { var cmd = Database.GetCustomCommand(CName); cmd.Reponse = resp; Database.AddOrUpdateCustomCommand(cmd); ChannelChat.Send($"Editted Command {CName}"); } }
public void Execute(ChatMessage msg, string[] parameters) { string message = "Custom Commands: "; foreach (var c in Core.Database.Database.CommandDB.FindAll()) { message += $"{c.CmdName}, "; } ChannelChat.Send(message == "Custom Commands: " ? "No Custom Commands Found" : message); }
public void Execute(ChatMessage msg, string[] parameters) { string message = ""; for (int i = 0; i < 7; i++) { message += $"{emotes[r.Next(emotes.Length)]} "; } ChannelChat.Send(message); }
public override IChat CreateChat(ChatType chatType, List <IUser> firstChatUsers, String chatName) { if (firstChatUsers.Count == 1) { IChat channelChat = new ChannelChat(firstChatUsers[0], chatName); _chatRepository.AddChat(channelChat); return(channelChat); } throw new InvalidDataException("The channel can only have one creator!"); }
public ChannelChat CreateChannelChat(IUser self) { int id = _idProvider.NextId; ChannelChat chat = new ChannelChat( id, new SequentialIdentityProvider(), new FileRepo <IMessage>($".{id}.msg"), new FileRepo <IMember>($".{id}.mbr") ); _chatRepo.Add(chat); // TODO: Add members return(chat); }
static void Main(string[] args) { Config.Load(); CommandHandler.RegisterCommands(); foreach (var command in CommandHandler.Commands) { Console.WriteLine($"Registered Command: {command.Command}"); } Bot = new TwitchBot(); Bot.Connect(); Console.WriteLine("\nPress Shift + X to exit\n\n"); while (true) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.X && (key.Modifiers & ConsoleModifiers.Shift) != 0) { Bot.Disconnect(); Thread.Sleep(250); break; } else if (key.Key == ConsoleKey.C) { Console.Write("Enter text to send >>> "); string text = Console.ReadLine(); if (text.StartsWith(".") || text.StartsWith("/")) { Console.WriteLine("Text cannot start with . or /"); continue; } if (string.IsNullOrEmpty(text) || string.IsNullOrWhiteSpace(text)) { Console.WriteLine("Text cannot be empty or only whitespace"); continue; } ChannelChat.Send(text); continue; } } }
public static void ProcessMessage(ChatMessage chatMsg) { string msg = chatMsg.Message.ToLower(); try { string[] parameters = GetParameters(chatMsg.Message); var foundCommand = Commands.FirstOrDefault(c => c.Command == msg.Split().FirstOrDefault()); foundCommand?.Execute(chatMsg, parameters.Skip(1).ToArray()); var customCommand = Database.Database.GetCustomCommand(parameters.FirstOrDefault().ToLower()); if (foundCommand == null && customCommand != null) { ChannelChat.Send(ChannelChat.FormatCustomCommandResponse(customCommand.Reponse, chatMsg)); } } catch (Exception e) { Console.Error.WriteLine($"An error occured executing a command:\n\nERROR: {e.Message}\n\nSTACKTRACE: \n{e.StackTrace}"); } }
public ChannelChatFixture(TestsFixture testsFixture, string collectionName) { _testsFixture = testsFixture; AddLifetime( initialize: async() => { _testsFixture.ChannelChat ??= await GetChat(collectionName); ChannelChat = _testsFixture.ChannelChat; ChannelChatId = ChannelChat.Username is null ? ChannelChat.Id.ToString() : $"@{ChannelChat.GetSafeUsername()}"; await _testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Tests will be executed in channel {ChannelChatId}" ); } ); }
public void Execute(ChatMessage msg, string[] parameters) { ChannelChat.Send("I'm a bot, not a personal assistant LUL"); }
public void Execute(ChatMessage msg, string[] parameters) { ChannelChat.Send("Please do not directly give awnsers, instead hint them towards the awnser/solution."); }
public void Execute(ChatMessage msg, string[] parameters) { ChannelChat.Send("Current Java Course: http://mooc.fi/english.html"); }
public void Execute(ChatMessage msg, string[] parameters) { string commands = "Commands: " + string.Join(", ", CommandHandler.Commands.Select(x => x.Command)); ChannelChat.Send(commands); }
public void Execute(ChatMessage msg, string[] parameters) { ChannelChat.Send("Discord Server: https://discord.gg/5DaYe6j"); }
public void Execute(ChatMessage msg, string[] parameters) { if (parameters.Length == 0) { ChannelChat.Send(usage); return; } if (int.TryParse(parameters[0], out int id)) { Quote quote = Database.GetQuote(id); if (quote != null) { ChannelChat.Send(quote.Text); } else { ChannelChat.Send($"No quote found by id: {id}"); } return; } else if (parameters[0].ToLower() == "random") { Quote[] quotes = Database.QuoteDB.FindAll().ToArray(); string quote = quotes.Length == 0 ? "No quotes found" : quotes[r.Next(quotes.Length)].Text; ChannelChat.Send(quote); return; } int quoteId; bool isEditOrDel = parameters[0].ToLower() == "del" || parameters[0].ToLower() == "edit"; if (!int.TryParse(parameters[1], out quoteId) && isEditOrDel) { ChannelChat.Send("Quote ID must be numeric"); return; } Quote q = Database.GetQuote(quoteId); switch (parameters[0].ToLower()) { case "del" when parameters.Length == 2: if (q != null) { Database.DeleteQuote(q); } ChannelChat.Send(q != null ? $"Deleted quote {quoteId}" : $"Could not find any quotes by id of {quoteId}"); break; case "add" when parameters.Length >= 1: string addText = string.Join(" ", parameters.Skip(1)); if (q == null) { Database.AddOrUpdateQuote(new Quote { Text = addText }); } ChannelChat.Send(q == null ? $"Added quote \"{addText}\" with id: {Database.QuoteDB.FindAll().LastOrDefault().Id}" : $"Quote already exist"); break; case "edit" when parameters.Length >= 2: string editText = string.Join(" ", parameters.Skip(2)); if (q != null) { q.Text = editText; Database.AddOrUpdateQuote(q); } ChannelChat.Send(q != null ? $"Updated quote {quoteId}" : $"Quote {quoteId} does not exist"); break; default: ChannelChat.Send("Invalid parameter, Usage: " + usage); break; } }