internal Command[] GetAllCommands(User user) { bool cmdHere = false; bool uptimeHere = false; foreach(Command comd in commands.ToArray<Command>()) { if (comd.Trigger == "!command") cmdHere = true; if (comd.Trigger == "!uptime") uptimeHere = true; } if (!addedStuff) { Command.delToDo uptimeDel = () => { string x = "Uptime: "; x += TwitchChatBot.me.timer.Hours + " hours, " + TwitchChatBot.me.timer.Minutes + " minutes, " + TwitchChatBot.me.timer.Seconds + " seconds."; TwitchChatBot.me.Client.SendChatMessage(x); }; Command uptime = new Command("!uptime", uptimeDel); commands.AddFirst(uptime); Command.delToDo creditsDel = () => { string x = "This bot was made by LezrecOP, shout out to my master <3"; TwitchChatBot.me.Client.SendChatMessage(x); }; Command credits = new Command("!credits", creditsDel); commands.AddFirst(credits); string schreiber = "My favorite teacher Kappa"; Command schrieb = new Command("!schreiber", schreiber); commands.AddFirst(schrieb); Command.delToDo commandsDel = () => { string x = "Commands: "; foreach (Command cmd in commands.ToArray<Command>()) { x += cmd.Trigger + ", "; } x = x.Substring(0, x.Length - 2); x += "."; TwitchChatBot.me.Client.Whisper(x, user); }; Command cmds = new Command("!commands", commandsDel); commands.AddFirst(cmds); addedStuff = true; } Command[] comds = commands.ToArray<Command>(); return commands.ToArray<Command>(); }
internal void AddToHead(Command comd) { if (!Contains(comd)) { commands.AddFirst(comd); if (!comingFromFile) { WriteToFile(); } } comingFromFile = false; }
internal void AddToTail(Command comd) { commands.AddLast(comd); }
internal Command RemoveCommand(Command command) { commands.Remove(command); WriteToFile(); return command; }
internal Command[] GetAllCommandsFromFile() { string all = TwitchChatBot.me.cmdsFromFile.ReadAllText(); if (all == "") return null; string[] splitUp = all.Split(new string[] { "NEW_LINE" }, StringSplitOptions.None); Command[] ret = new Command[splitUp.Length]; for(int i = 0; i < ret.Length; i++) { string modify = splitUp[i]; if (modify == "") return ret; modify = modify.Substring(1); int whereTrigger = modify.IndexOf(","); string trigger = modify.Substring(0, whereTrigger); modify = modify.Substring(whereTrigger + 1); string todo = modify; ret[i] = new Command(trigger, todo); } return ret; }
internal bool Contains(Command comd) { Command[] all = GetAllCommands(TwitchChatBot.THE_MAN); foreach(Command c in all) { if (c.Trigger == comd.Trigger) { return true; } } return false; }
private void AddCommand(string trigger, string todo) { for (int i = 0; i < TwitchChatBot.me.cmdList.GetAllTriggers().Length; i++) { if (trigger == TwitchChatBot.me.cmdList.GetAllTriggers()[i]) { return; //makes sure that you cant add a command that does 2 things } } Command command = new Command(trigger, todo); TwitchChatBot.me.cmdList.AddToHead(command); GuiManager.WriteToCommands(); }