Last active
December 17, 2015 23:39
-
-
Save CalmBit/5691385 to your computer and use it in GitHub Desktop.
BlueBots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
class BotBase | |
{ | |
public string name; | |
public ConsoleColor color; | |
public const string version = "0.1a"; | |
public int currentStatus; | |
public bool debug; | |
public BotBase(string name, ConsoleColor color, bool debug) | |
{ | |
this.name = name; | |
this.color = color; | |
this.debug = debug; | |
} | |
public void sayMessage(string message) | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[BOT] "); | |
Console.ForegroundColor = this.color; | |
Console.Write(this.name + ": "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine(message); | |
} | |
public void returnError(int code) | |
{ | |
Console.ForegroundColor = ConsoleColor.DarkCyan; | |
Console.Write("[CONSOLE] "); | |
Console.ForegroundColor = color; | |
Console.Write(name + " "); | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine("Has encountered an error. Code " + code); | |
currentStatus = code; | |
Console.WriteLine("Returning To Console..."); | |
} | |
public bool handleString(string message, string user) | |
{ | |
if (debug) | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[BOT]"); | |
Console.ForegroundColor = this.color; | |
Console.Write(" " + this.name + " "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.Write("Recieved Message : " + message + "\n"); | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Yellow; | |
Console.Write(user + ": "); | |
Console.WriteLine(message); | |
} | |
if (message.Substring(0, 1) == "!") | |
{ | |
switch (message) | |
{ | |
case "!hello": | |
this.sayMessage("Hello, " + user + "!"); | |
break; | |
case "!version": | |
this.sayMessage("BlueBot Framework Version " + version + "."); | |
break; | |
case "!credits": | |
this.sayMessage("Code: Ethan Brooks"); | |
this.sayMessage("BlueFeather Solutions LLC, 2013 (C). All Rights Reserved."); | |
break; | |
case "!quit": | |
currentStatus = 2; | |
break; | |
case "!error": | |
this.returnError(1); | |
break; | |
case "!help": | |
this.sayMessage("!hello,!version,!credits,!quit,!error!,!help"); | |
break; | |
default: | |
this.sayMessage("I don't know that command!"); | |
break; | |
} | |
return false; | |
} | |
else this.sayMessage("That wasn't a command!"); | |
return false; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
public bool isQRequested = false; | |
public String currentMessage; | |
public int statusCode; | |
public BotBase[] allBots; | |
public string version = "0.1a"; | |
public int currentBot; | |
public string username; | |
public void exit() | |
{ | |
Console.ForegroundColor = ConsoleColor.Gray; | |
Console.WriteLine("Shutting Down..."); | |
} | |
public void login(string username) | |
{ | |
this.username = username; | |
Console.ForegroundColor = ConsoleColor.DarkMagenta; | |
Console.WriteLine("Logged in as " + username); | |
} | |
public void mainTickCycle() | |
{ | |
while (!isQRequested) | |
{ | |
if (currentBot > 0 && currentBot <= allBots.Length && statusCode == 0) | |
{ | |
Console.ForegroundColor = ConsoleColor.Green; | |
Console.Write("Command: "); | |
Console.ForegroundColor = ConsoleColor.White; | |
currentMessage = Console.ReadLine(); | |
if (username != null) isQRequested = allBots[currentBot].handleString(currentMessage, username); | |
else isQRequested = allBots[currentBot].handleString(currentMessage, "Anon"); | |
statusCode = allBots[currentBot].currentStatus; | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.Write("Command: "); | |
Console.ForegroundColor = ConsoleColor.White; | |
currentMessage = Console.ReadLine(); | |
switch (currentMessage) | |
{ | |
case "!bot": | |
changeBot(); | |
break; | |
case "!quit": | |
isQRequested = true; | |
break; | |
case "!resetBots": | |
for(int i = 1; i < 10;i++) | |
{ | |
if(allBots[i] != null) | |
{ | |
allBots[i].currentStatus = 0; | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.ForegroundColor = ConsoleColor.White; | |
} | |
} | |
Console.WriteLine("All bots have been reset."); | |
break; | |
case "!version": | |
this.broadcastMessage("BlueBots Version " + version); | |
this.broadcastMessage("BlueBot Model is at " + BotBase.version); | |
break; | |
case "!list": | |
for (int i = 1; i < 10; i++) | |
{ | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.Write("Bot " + i + ": "); | |
if (allBots[i] != null) | |
{ | |
Console.ForegroundColor = allBots[i].color; | |
Console.WriteLine(allBots[i].name); | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine("Not Avalible!"); | |
} | |
} | |
break; | |
case "!login": | |
while (username == null || username == "") | |
{ | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.Write("Username: "); | |
Console.ForegroundColor = ConsoleColor.White; | |
username = Console.ReadLine(); | |
if (username == null || username == "") | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[ERROR] "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("Username is empty!"); | |
} | |
else | |
{ | |
login(username); | |
} | |
} | |
break; | |
case "!logout": | |
username = null; | |
Console.ForegroundColor = ConsoleColor.DarkMagenta; | |
Console.WriteLine("Logged out."); | |
Console.ForegroundColor = ConsoleColor.White; | |
break; | |
default: | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[ERRROR] "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("Not A Command!"); | |
break; | |
} | |
} | |
} | |
exit(); | |
} | |
public void init() | |
{ | |
allBots = new BotBase[10]; | |
allBots[0] = null; | |
Console.ForegroundColor = ConsoleColor.Gray; | |
Console.WriteLine("BlueBots Version " + version); | |
Console.WriteLine("Booting up..."); | |
Console.ForegroundColor = ConsoleColor.White; | |
registerBot(1,new BotBase("BlueBot", ConsoleColor.Blue, false)); | |
registerBot(2,new BotBase("GreenBot", ConsoleColor.Green, false)); | |
mainTickCycle(); | |
} | |
public void broadcastMessage(string message) | |
{ | |
Console.ForegroundColor = ConsoleColor.DarkCyan; | |
Console.Write("[CONSOLE] "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine(message); | |
} | |
public void registerBot(int id, BotBase bot) | |
{ | |
allBots[id] = bot; | |
Console.ForegroundColor = ConsoleColor.DarkCyan; | |
Console.Write("[CONSOLE] "); | |
Console.ForegroundColor = bot.color; | |
Console.Write(bot.name + " "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("has been added to slot " + id); | |
} | |
public void changeBot() | |
{ | |
Console.ForegroundColor = ConsoleColor.Green; | |
Console.Write("Bot Number: "); | |
Console.ForegroundColor = ConsoleColor.White; | |
currentMessage = Console.ReadLine(); | |
if (currentMessage.Length >= 5 || Convert.ToInt32(currentMessage) > 10 || Convert.ToInt32(currentMessage) == 0) | |
{ | |
Console.WriteLine(currentMessage.Length <= 5); | |
Console.WriteLine(Convert.ToInt32(currentMessage) > 10); | |
Console.WriteLine(Convert.ToInt32(currentMessage) == 0); | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[ERRROR] "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("Bot Number " + Convert.ToInt32(currentMessage) + " does not exist!"); | |
} | |
else | |
{ | |
if (allBots[Convert.ToInt32(currentMessage)] != null) | |
{ | |
currentBot = Convert.ToInt32(currentMessage); | |
if (allBots[currentBot].currentStatus == 1) | |
{ | |
allBots[currentBot].sayMessage("I'm undergoing maintenance or have encountered an error. Check back soon!"); | |
} | |
else | |
{ | |
statusCode = 0; | |
allBots[currentBot].currentStatus = 0; | |
Console.ForegroundColor = ConsoleColor.Blue; | |
Console.Write("Now Chatting With: "); | |
Console.ForegroundColor = allBots[currentBot].color; | |
Console.WriteLine(allBots[currentBot].name); | |
Console.ForegroundColor = ConsoleColor.White; | |
} | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.Write("[ERRROR] "); | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("Bot Number " + Convert.ToInt32(currentMessage) + " does not exist!"); | |
} | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Program p = new Program(); | |
p.init(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment