public Alice(Player player_) { player = player_; myBot = new AIMLbot.Bot(); myUser = new User(player.Name, myBot);//y wont u set my name Initialize(); }
public string GetResp(string msg, string user) { try { myUser = null; //GC.Collect(); myUser = new AIMLbot.User(user, myBot); AIMLbot.Request myRequest = new AIMLbot.Request(msg, myUser, myBot); AIMLbot.Result myResult = myBot.Chat(myRequest); string reply = myResult.Output; if (reply.Length > 5) { if (reply.Substring(0, 5).ToLower(CultureInfo.CurrentCulture) == "error") { return string.Empty; } return reply; } return reply; } catch (Exception ex) { Logger.Log("There has been an error starting AI.", Helpers.LogLevel.Warning, ex); return string.Empty; } }
static void Main(string[] args) { _bot = InstantiateBot(); _user = new User("chris", _bot); var input = string.Empty; Console.WriteLine("Say somthing to begin teaching me."); while (input.ToLower() != "q") { input = GetUserInput(); if (input.StartsWith("/")) { if (input.StartsWith("/bot")) ProcessBotCommand(input); if (input == "/save") { SaveBot(); continue; } } var request = new Request(input, _user, _bot); var response = _bot.Chat(request); TellUser(response); } }
/// <summary> /// Ctor /// </summary> /// <param name="user">The user for whom this is a result</param> /// <param name="bot">The bot providing the result</param> /// <param name="request">The request that originated this result</param> public Result(User user, Bot bot, Request request) { this.user = user; this.bot = bot; this.request = request; this.request.result = this; }
/// <summary> /// Ctor /// </summary> /// <param name="rawInput">The raw input from the user</param> /// <param name="user">The user who made the request</param> /// <param name="bot">The bot to which this is a request</param> public Request(string rawInput, User user, Bot bot) { this.rawInput = rawInput; this.user = user; this.bot = bot; this.StartedOn = DateTime.Now; }
public QueryParser() { ChatBot.loadSettings(); ChatUser = new User(UserId, ChatBot); ChatBot.loadAIMLFromFiles(); ChatBot.isAcceptingUserInput = true; }
/// <summary> /// Creates an instance of the Request object. /// </summary> /// <param name="rawInput">The raw input from the user</param> /// <param name="user">The user who made the request</param> public Request(string rawInput, User user) { RawInput = rawInput; User = user; StartedOn = DateTime.Now; EndTime = StartedOn.AddMilliseconds(ChatBot.TimeOut); }
//methods public bool initialize_iBOT() { //initialize bot bot = new Bot(); bot.loadSettings(); //TODO: change settings.xml in config //user settings user = new User("DefaultUser", this.bot); //Log writer event setting bot.WrittenToLog += new Bot.LogMessageDelegate(bot_Log); //Initialize the bot's Mind try { AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.bot); this.bot.isAcceptingUserInput = false; loader.loadAIML(AIMLSourcePath); this.bot.isAcceptingUserInput = true; } catch (Exception ex) { ExceptionMsgs += DateTime.Now.ToString() + ">> " + ex.Message + Environment.NewLine; return false; } //the bot is ready to serve! initialized = true; return true; }
void Start() { // Debug.Log("aaaaa"); LogSystem.InstallDefaultReactors(); // Create credential and instantiate service Credentials credentials = new Credentials("c20a3f60-9df3-4d5b-86e5-027ccde5c42c", "mnCUwtXFpNSl", "https://gateway.watsonplatform.net/conversation/api"); _conversation = new Conversation(credentials); _conversation.VersionDate = _conversationVersionDate; bot = new AIMLbot.Bot(); user = new AIMLbot.User("User", bot); request = new AIMLbot.Request("", user, bot); result = new AIMLbot.Result(user, bot, request); bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml"); // Load AIML files from AIML path defined in Settings.xml bot.loadAIMLFromFiles(); if (bot != null) { bot.UseJavaScript = true; } // TextToSpeechMark ttsm = gameObject.GetComponent<TextToSpeechMark>(); // AskQuestion(); }
public void testResultHandlers() { this.mockUser = new User("1", this.mockBot); Assert.AreEqual("", this.mockUser.getResultSentence()); Request mockRequest = new Request("Sentence 1. Sentence 2", this.mockUser, this.mockBot); Result mockResult = new Result(this.mockUser, this.mockBot, mockRequest); mockResult.InputSentences.Add("Result 1"); mockResult.InputSentences.Add("Result 2"); mockResult.OutputSentences.Add("Result 1"); mockResult.OutputSentences.Add("Result 2"); this.mockUser.addResult(mockResult); Result mockResult2 = new Result(this.mockUser, this.mockBot, mockRequest); mockResult2.InputSentences.Add("Result 3"); mockResult2.InputSentences.Add("Result 4"); mockResult2.OutputSentences.Add("Result 3"); mockResult2.OutputSentences.Add("Result 4"); this.mockUser.addResult(mockResult2); Assert.AreEqual("Result 3", this.mockUser.getResultSentence()); Assert.AreEqual("Result 3", this.mockUser.getResultSentence(0)); Assert.AreEqual("Result 1", this.mockUser.getResultSentence(1)); Assert.AreEqual("Result 4", this.mockUser.getResultSentence(0, 1)); Assert.AreEqual("Result 2", this.mockUser.getResultSentence(1, 1)); Assert.AreEqual("", this.mockUser.getResultSentence(0, 2)); Assert.AreEqual("", this.mockUser.getResultSentence(2, 0)); Assert.AreEqual("Result 3", this.mockUser.getThat()); Assert.AreEqual("Result 3", this.mockUser.getThat(0)); Assert.AreEqual("Result 1", this.mockUser.getThat(1)); Assert.AreEqual("Result 4", this.mockUser.getThat(0, 1)); Assert.AreEqual("Result 2", this.mockUser.getThat(1, 1)); Assert.AreEqual("", this.mockUser.getThat(0, 2)); Assert.AreEqual("", this.mockUser.getThat(2, 0)); }
static void Main(string[] args) { AIMLbot.Bot chatBot; AIMLbot.User chatUser; string channel = args[0]; string rnick = args[1]; string rmsg = args[2]; try { if (rmsg.StartsWith("!") == false) { string query = rmsg; ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions(); chatBot = new AIMLbot.Bot(); chatBot.loadSettings(); chatUser = new AIMLbot.User(rnick, chatBot); chatBot.loadAIMLFromFiles(); chatBot.isAcceptingUserInput = true; AIMLbot.Request r = new AIMLbot.Request(query, chatUser, chatBot); AIMLbot.Result res = chatBot.Chat(r); Console.WriteLine("PRIVMSG " + rnick + " :" + res.Output); } } catch (Exception ex) { Console.WriteLine("PRIVMSG " + rnick + " :" + ex.ToString()); } }
public void testResultHandlers() { this.mockUser = new User("1", this.mockBot); Assert.AreEqual("", this.mockUser.getResultSentence()); Request mockRequest = new Request("Sentence 1. Sentence 2",this.mockUser,this.mockBot); Result mockResult = new Result(this.mockUser, this.mockBot, mockRequest); mockResult.InputSentences.Add("Result 1"); mockResult.InputSentences.Add("Result 2"); mockResult.OutputSentences.Add("Result 1"); mockResult.OutputSentences.Add("Result 2"); this.mockUser.addResult(mockResult); Result mockResult2 = new Result(this.mockUser, this.mockBot, mockRequest); mockResult2.InputSentences.Add("Result 3"); mockResult2.InputSentences.Add("Result 4"); mockResult2.OutputSentences.Add("Result 3"); mockResult2.OutputSentences.Add("Result 4"); this.mockUser.addResult(mockResult2); Assert.AreEqual("Result 3", this.mockUser.getResultSentence()); Assert.AreEqual("Result 3", this.mockUser.getResultSentence(0)); Assert.AreEqual("Result 1", this.mockUser.getResultSentence(1)); Assert.AreEqual("Result 4", this.mockUser.getResultSentence(0, 1)); Assert.AreEqual("Result 2", this.mockUser.getResultSentence(1, 1)); Assert.AreEqual("", this.mockUser.getResultSentence(0, 2)); Assert.AreEqual("", this.mockUser.getResultSentence(2, 0)); Assert.AreEqual("Result 3", this.mockUser.getThat()); Assert.AreEqual("Result 3", this.mockUser.getThat(0)); Assert.AreEqual("Result 1", this.mockUser.getThat(1)); Assert.AreEqual("Result 4", this.mockUser.getThat(0, 1)); Assert.AreEqual("Result 2", this.mockUser.getThat(1, 1)); Assert.AreEqual("", this.mockUser.getThat(0, 2)); Assert.AreEqual("", this.mockUser.getThat(2, 0)); }
public string GetResp(string msg, string user) { try { myUser = null; //GC.Collect(); myUser = new AIMLbot.User(user, myBot); AIMLbot.Request myRequest = new AIMLbot.Request(msg, myUser, myBot); AIMLbot.Result myResult = myBot.Chat(myRequest); string reply = myResult.Output; if (reply.Length > 5) { if (reply.Substring(0, 5).ToLower(CultureInfo.CurrentCulture) == "error") { return(string.Empty); } return(reply); } return(reply); } catch (Exception ex) { Logger.Log("There has been an error starting AI.", Helpers.LogLevel.Warning, ex); return(string.Empty); } }
private static async void BotOnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { Bot.Types.Message msg = e.Message; if (msg == null) { return; } if (msg.Type == Bot.Types.Enums.MessageType.TextMessage) { AIMLbot.Bot AI = new AIMLbot.Bot(); AI.loadSettings(); // This loads the settings from the config folder AI.loadAIMLFromFiles(); AIMLbot.User me_aiml = new AIMLbot.User("dd", AI); Request r = new Request(msg.Text, me_aiml, AI); Result res = AI.Chat(r); string s = res.ToString(); await bot.SendTextMessageAsync(msg.Chat.Id, s); } //if (msg.Type == Bot.Types.Enums.MessageType.TextMessage) //{ // //await bot.SendTextMessageAsync(msg.Chat.Id, "Здарова " + msg.From.FirstName //} }
/// <summary> /// Given an input string, return an output from the bot. /// </summary> /// <param name="input">string</param> /// <param name="user">User (so conversations can be tracked by the bot, per user)</param> /// <returns>string</returns> public String getOutput(String input, User user) { Request r = new Request(input, user, this); Result res = Chat(r); return (res.Output); }
static void Main(string[] args) { string settingsPath = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml")); Bot myBot = new Bot(); myBot.loadSettings(settingsPath); User myUser = new User("consoleUser", myBot); myBot.isAcceptingUserInput = false; myBot.loadAIMLFromFiles(); myBot.isAcceptingUserInput = true; while (true) { Console.Write("You: "); string input = Console.ReadLine(); if (input.ToLower() == "quit") { break; } else { Request r = new Request(input, myUser, myBot); Result res = myBot.Chat(r); Console.WriteLine("Bot: " + res.Output); } } }
/// <summary> /// Creates an instance of the Result class. /// </summary> /// <param name="user">The user for whom this is a result</param> /// <param name="request">The request that originated this result</param> public Result(User user, Request request) { User = user; Request = request; Request.Result = this; _splitters = ChatBot.Splitters.ToArray(); }
/// <summary> /// Returns a response from the message received. /// The response comes from our AIML chat bot or from our own custom processing. /// </summary> /// <param name="message">string</param> /// <param name="user">User (for context)</param> /// <returns>string</returns> private static string HandleMessage(string message, User user) { string output = ""; if (!string.IsNullOrEmpty(message)) { // Provide custom commands for our chat bot, such as disk space, utility functions, typical IRC bot features, etc. if (message.ToUpper().IndexOf("DISK SPACE") != -1) { DriveInfo driveInfo = new DriveInfo("C"); output = "Available disk space on " + driveInfo.Name + " is " + driveInfo.AvailableFreeSpace + "."; } else if (message.ToUpper().IndexOf("DISK SIZE") != -1) { DriveInfo driveInfo = new DriveInfo("C"); output = "The current disk size on " + driveInfo.Name + " is " + driveInfo.TotalSize + "."; } else { // No recognized command. Let our chat bot respond. output = _bot.getOutput(message, user); } } return output; }
public void testConstructorPopulatesUserObject() { this.mockUser = new User("1", this.mockBot); Assert.AreEqual("*", this.mockUser.Topic); Assert.AreEqual("1", this.mockUser.UserID); // the +1 in the following assert is the creation of the default topic predicate Assert.AreEqual(this.mockBot.DefaultPredicates.SettingNames.Length + 1, this.mockUser.Predicates.SettingNames.Length); }
public void testConstructorPopulatesUserObject() { this.mockUser = new User("1", this.mockBot); Assert.AreEqual("*", this.mockUser.Topic); Assert.AreEqual("1", this.mockUser.UserID); // the +1 in the following assert is the creation of the default topic predicate Assert.AreEqual(this.mockBot.DefaultPredicates.SettingNames.Length+1, this.mockUser.Predicates.SettingNames.Length); }
public void Test() { var bot = new Bot(); var user = new User("me", bot); var request = new Request("test", user, bot); var result = bot.Chat(request); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); }
public Form1() { InitializeComponent(); _myBot = new Bot(); _myBot.loadSettings(); _myUser = new User("consoleUser", _myBot); _synth = new SpeechSynthesizer(); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockBot.loadAIMLFromFiles(); this.mockUser = new User("1", this.mockBot); //this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); //this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); }
public ChatBot(string userId) { this.bot = new Bot(); this.bot.loadSettings(); this.user = new User(userId, this.bot); this.bot.isAcceptingUserInput = false; this.bot.loadAIMLFromFiles(); this.bot.isAcceptingUserInput = true; }
public aimlForm() { InitializeComponent(); this.toolStripMenuItemSpeech.Checked = true; this.richTextBoxInput.Focus(); myBot = new Bot(); myBot.loadSettings(); myUser = new User("DefaultUser",this.myBot); myBot.WrittenToLog += new Bot.LogMessageDelegate(myBot_WrittenToLog); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockQuery.InputStar.Insert(0, "first star"); this.mockQuery.InputStar.Insert(0, "second star"); //this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); }
public MainWindow() { bot = new Bot(); user = new User("DefaultUser", bot); bot.loadSettings(); AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(bot); bot.isAcceptingUserInput = false; loader.loadAIML(bot.PathToAIML); bot.isAcceptingUserInput = true; InitializeComponent(); }
public HotShotBot() { //------I added this code just coz I love that Light Green Geeky Looking Console ;-)------ //Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Green; //---------------------------------------------------------------------------------------- AimlBot = new Bot(); myUser = new User(UserId, AimlBot); Console.Title = "HotShotBot v1.0 - By Vivek Yadav (www.Shellvhack.com)"; Initialize(); }
public string Ask(string name, string question) { var sharpBot = new Bot(); sharpBot.loadSettings(SettingsPath); var loader = new AIMLbot.Utils.AIMLLoader(sharpBot); loader.loadAIML(aimlPath); sharpBot.isAcceptingUserInput = false; sharpBot.isAcceptingUserInput = true; var patient = new User(name, sharpBot); var request = new Request(question, patient, sharpBot); var answer = sharpBot.Chat(request); return answer.Output; }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); this.possibleResults = new ArrayList(); this.possibleResults.Add("random 1"); this.possibleResults.Add("random 2"); this.possibleResults.Add("random 3"); this.possibleResults.Add("random 4"); this.possibleResults.Add("random 5"); }
/// <summary> /// Returns a User from cache or creates a new one, based upon their Gmail username, allowing the bot to track conversations per user. /// </summary> /// <param name="jid">unique string ID (gmail username)</param> /// <returns>User</returns> public static User GetUser(string jid, Bot bot) { // Maintain sticky sessions with specific users, allows bot to remember them. Hashtable myHash = Hashtable.Synchronized(_userSessions); User user = (User)myHash[jid]; if (user == null) { user = new User(jid, bot); myHash[jid] = user; } return user; }
public myUser(string user, ref RichTextBox richTextBox, Bot theBot, string userFullName, Chat theChat) { userName = user; textBox = richTextBox; AIusr = new AIMLbot.User(user, theBot); chat = theChat; if (userFullName != "") { AIusr.Predicates.updateSetting("name", userFullName); } else { AIusr.Predicates.updateSetting("name", user); } }
/// <summary> /// Initialize our derived MonoBehaviour /// </summary> void Start() { CommText = GameObject.Find("CommText").GetComponent <Text>(); ResponseText = GameObject.Find("ResponseText").GetComponent <Text>(); bot = new AIMLbot.Bot(); user = new AIMLbot.User("User", bot); request = new AIMLbot.Request("", user, bot); result = new AIMLbot.Result(user, bot, request); bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml"); bot.loadAIMLFromFiles(); if (bot != null) { bot.UseJavaScript = true; } }
public chat() { chat_time.AutoReset = false; chat_time.Elapsed += stop_chat; chat_time.Enabled = false; still_chatting = false; chatting_nick = new List<string>(); myBot = new Bot(); myBot.loadSettings(); myUser = new User("chat_nick", myBot); AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(myBot); myBot.isAcceptingUserInput = false; loader.loadAIML(myBot.PathToAIML); myBot.isAcceptingUserInput = true; }
// public void do_first() { Bot myBot = new Bot(); const string UserId = "Team Atlas"; myBot.loadSettings(); User myUser = new User(UserId, myBot); myBot.isAcceptingUserInput = false; myBot.loadAIMLFromFiles(); myBot.isAcceptingUserInput = true; setBot(myBot); setUser(myUser); //nick : creating Speech Synthesizer events sSynth.SetOutputToDefaultAudioDevice(); sSynth.SpeakStarted += new EventHandler<SpeakStartedEventArgs>(synth_SpeakStarted); sSynth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted); // }
public ChatRobotOperator(string userName) { bot = new Bot(); bot.loadSettings(); user = new User(userName, bot); //try //{ AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(bot); bot.isAcceptingUserInput = false; loader.loadAIML(bot.PathToAIML); bot.isAcceptingUserInput = true; //} //catch (Exception ex) //{ // //this.outputRichTextBox.AppendText(ex.Message + Environment.NewLine); //} }
/// <summary> /// Initialize our derived MonoBehaviour /// </summary> void Start() { // Initialize Program # variables // For Webplayer plattform and WebGl #if (UNITY_WEBPLAYER || UNITY_WEBGL) ProgramSharpWebplayerCoroutine WebplayerCoroutine = this.gameObject.GetComponent <ProgramSharpWebplayerCoroutine>(); if (WebplayerCoroutine != null) { bot = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/config/Settings.xml"); } else { Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode."); } // Other plattforms #else // Only for Windows, Linux and Mac OSX bot = new AIMLbot.Bot(); #endif user = new AIMLbot.User("User", bot); request = new AIMLbot.Request("", user, bot); result = new AIMLbot.Result(user, bot, request); // Only for Windows, Linux, Mac OSX Android and IOS #if !(UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_ANDROID || UNITY_IOS) // Load Settings from Xml file in config directory. Plattform dependend Path issues may // occur. bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml"); // Load AIML files from AIML path defined in Settings.xml bot.loadAIMLFromFiles(); #endif // Android and IOS release #if (UNITY_ANDROID || UNITY_IOS) // Load Settings from Xml file in config directory within resources folder. bot.loadSettings("Chatbot/Program #/config/Settings"); // Load AIML files from AIML path defined in Settings.xml bot.loadAIMLFromFiles(); #endif // Define to or not to use JavaScript (Jurassic) in AIML if (bot != null) { bot.UseJavaScript = true; } }
public DiscoBot(string TOKEN) { // Setup AIML Bot AI = new Bot(); AI.loadSettings(); AI.loadAIMLFromFiles(); AI.isAcceptingUserInput = false; // Setup User AIMLbot.User myUser = new AIMLbot.User("Username", AI); AI.isAcceptingUserInput = true; // Discord Settings _DiscordClient = new DiscordClient(x => { x.LogLevel = LogSeverity.Info; x.LogHandler = log; }); _DiscordClient.UsingCommands(x => { x.PrefixChar = '+'; x.AllowMentionPrefix = true; }); var commands = _DiscordClient.GetService <CommandService>(); // A list of all commands commands.CreateCommand("help") .Do(async(e) => { await e.Channel.SendMessage("Get help with +help <text>"); await e.Channel.SendMessage("Send a message with ++ <text>"); await e.Channel.SendMessage("Check Version with +version <text>"); await e.Channel.SendMessage("Change the bot state with +IsActive <true|false>"); await e.Channel.SendMessage("The bot speaks if true with TLS <true|false>"); }); commands.CreateCommand("+") .Parameter("words", ParameterType.Unparsed) .Do(async(e) => { // do if enabled if (_IsActive == true) { // Get text string s = e.GetArg("words"); // Send request Request r = new Request(s, myUser, AI); // Save answer Result res = AI.Chat(r); if (_IsSpeaking == true) { // Use TLS to say message await e.Channel.SendTTSMessage(res.Output); } else { // Output answer await e.Channel.SendMessage(res.Output); } } }); commands.CreateCommand("version") .Do(async(e) => { // Send version await e.Channel.SendMessage("Chatter v1.1"); }); commands.CreateCommand("IsActive") .Parameter("input", ParameterType.Unparsed) .AddCheck((cm, u, ch) => u.ServerPermissions.Administrator) .Do(async(e) => { // Input try { // get set value _IsActive = Convert.ToBoolean(e.GetArg("input")); // confirm user await e.Channel.SendMessage((_IsActive == true) ? "activated" : "deactivated"); } catch { await e.Channel.SendMessage("Invalid input!"); } }); commands.CreateCommand("IsSpeaking") .Parameter("input", ParameterType.Unparsed) .AddCheck((cm, u, ch) => u.ServerPermissions.Administrator) .Do(async(e) => { // Input try { // get set value _IsSpeaking = Convert.ToBoolean(e.GetArg("input")); // confirm user await e.Channel.SendMessage((_IsSpeaking == true) ? "activated" : "deactivated"); } catch { await e.Channel.SendMessage("Invalid input!"); } }); // Build connection _DiscordClient.ExecuteAndWait(async() => { await _DiscordClient.Connect(TOKEN, TokenType.Bot); }); }
public void testBadConstructor() { Action act = () => this.mockUser = new User("", this.mockBot); Assert.Throws <Exception>(act); }
async void do_work(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; var key = e.Argument as String; try { var bot = new Telegram.Bot.TelegramBotClient(key); await bot.SetWebhookAsync(""); AIMLbot.Bot lazy = new AIMLbot.Bot(); lazy.loadSettings(); lazy.loadAIMLFromFiles(); lazy.isAcceptingUserInput = false; AIMLbot.User us = new AIMLbot.User("Username", lazy); lazy.isAcceptingUserInput = true; bot.OnCallbackQuery += async(object sc, Telegram.Bot.Args.CallbackQueryEventArgs ev) => { Telegram.Bot.Types.FileToSend s; var message = ev.CallbackQuery.Message; if (ev.CallbackQuery.Data == "callback1") { s = new Telegram.Bot.Types.FileToSend("https://i.pinimg.com/originals/f7/e9/80/f7e980c9700c8395535b835e66f02a59.jpg"); } else if (ev.CallbackQuery.Data == "callback2") { s = new Telegram.Bot.Types.FileToSend("https://static.independent.co.uk/s3fs-public/thumbnails/image/2012/02/29/22/pg-28-sloth-cooke.jpg"); } await bot.SendPhotoAsync(message.Chat.Id, s, "Sure! But... not today :)"); await bot.AnswerCallbackQueryAsync(ev.CallbackQuery.Id); }; bot.OnUpdate += async(object su, Telegram.Bot.Args.UpdateEventArgs evu) => { if (evu.Update.CallbackQuery != null || evu.Update.InlineQuery != null) { return; } var update = evu.Update; var message = update.Message; if (message == null) { return; } if (message.Type == Telegram.Bot.Types.Enums.MessageType.TextMessage) { if (message.Text[0] == '/') { if (message.Text == "/test") { await bot.SendTextMessageAsync(message.Chat.Id, "Yeah...", replyToMessageId : message.MessageId); } if (message.Text == "/sleep") { var s = new Telegram.Bot.Types.FileToSend("https://beano-uploads-production.imgix.net/store/f4046f22dffe92e3f2167accb6942f788159d0f979f970dcda59f1d0e529?auto=compress&w=752&h=423&fit=min"); await bot.SendPhotoAsync(message.Chat.Id, s, "Yeeeeeeeeeah, sleeeeeeeeep!"); } if (message.Text == "/song") { var s = new Telegram.Bot.Types.FileToSend("http://store.naitimp3.ru/download/0/cGR1a0tRTWJwZW8wMlI2aitkT1UzVkxNdXE2dUNiRTAvcGRkeGphMTVFVTdQcGFURWlFOFQyUGZFTXJ6UVo4cWxVSUNza2NOQUpoZkJOU2ozYTJhWUpLSVdiUTRTanQrVmZnN1hQV1U5Tkk9/eels_i_need_some_sleep_(NaitiMP3.ru).mp3"); await bot.SendAudioAsync(message.Chat.Id, s, "", 4, "Eels", "I need some sleep..."); } if (message.Text == "/work") { var keyboard = new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardMarkup( new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardButton[][] { // First row new [] { // First column new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardCallbackButton("Work", "callback1"), // Second column new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardCallbackButton("Work harder", "callback2") }, } ); await bot.SendTextMessageAsync(message.Chat.Id, "Hmmmm... What should I do?..!", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0, keyboard); } } else if ((message.Text[0] >= 'а' && message.Text[0] <= 'я') || (message.Text[0] >= 'А' && message.Text[0] <= 'Я')) { await bot.SendTextMessageAsync(message.Chat.Id, "I'm too lazy to learn russian, sorry...", replyToMessageId : message.MessageId); } else { AIMLbot.Request r = new AIMLbot.Request(message.Text, us, lazy); AIMLbot.Result res = lazy.Chat(r); await bot.SendTextMessageAsync(message.Chat.Id, res.Output, replyToMessageId : message.MessageId); } } }; bot.StartReceiving(); } catch (Telegram.Bot.Exceptions.ApiRequestException ex) { Console.WriteLine(ex.Message); } }
public void testBadConstructor() { this.mockUser = new User("", this.mockBot); }
public RequestTests() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); }
public ResultTests() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); mockRequest = new Request("This is a test", this.mockUser, this.mockBot); }