public void OnMessageCallback(Connection conn, InstantMessage im) { lock (this) { log.InfoFormat("INMSG ({0}) << {1}: {2}", conn.GetType().Name, im.User, im.Text); DateTime dtStart = DateTime.Now; try { ResponseChannel = new ResponseChannel(im.User, conn); VBotService.RequestResult result = BotService.Instance.WhoAmI(BotService.Credentialize(ResponseChannel)); if (result.Code == 0) { LocalUser user = LocalUser.GetUser(ResponseChannel, result.RemoteUser); #region if if (_inputs.ContainsKey(user.LocalUserID) && _inputs[user.LocalUserID].State == InputStateEnum.Waiting) { // waiting for input? InputState ist = new InputState(InputStateEnum.Responded); ist.PageText = im.Text; _inputs[user.LocalUserID] = ist; } else { // the user is at the 'main menu' Result lastRes = new Result(); string[] strCommands = Regex.Split(im.Text, @"\;"); foreach (string strCommand in strCommands) { lastRes = DoCommand(strCommand, user); if (lastRes.Code != ResultCode.Success) { break; } } if (lastRes != null && (lastRes.Code == ResultCode.Success || lastRes.Code == ResultCode.Error)) { conn.SendMessage(new InstantMessage(im.User, lastRes.Message)); } } #endregion } else { log.ErrorFormat("GetUser failed: {0}", result.Text); ResponseChannel.SendMessage(ResponseChannel.FetchTemplate(result.Text)); } } catch (Exception ex) { log.Error("Something bad",ex); } if (log.IsDebugEnabled) { TimeSpan elapsed = DateTime.Now - dtStart; log.InfoFormat("Response Time: {0}.{1} seconds",elapsed.Seconds, elapsed.Milliseconds); } } }
public void postNotificationElapsed(object sender, ElapsedEventArgs e) { log.Info("Notification Timer Elapsed()"); if (_conComp.Connections != null && _conComp.Connections.Count() > 0) { VBotService.PostNotificationsResult result = BotService.Instance.GetPostNotifications(false); if (result.Result.Code == 0) { if (result.PostNotificationList != null && result.PostNotificationList.Count() > 0) { log.Info(string.Format("{0} post notifications recieved", result.PostNotificationList.Count())); foreach (VBotService.PostNotification not in result.PostNotificationList) { Connection c = _conComp.GetConnection(not.IMNotificationInfo.InstantIMService); if (c != null) { string strScreenName = not.IMNotificationInfo.InstantIMScreenname; string strResponse = c.NewLine + "Forum: '" + not.Forum.Title + "'" + c.NewLine + "Thread: '" + not.Thread.ThreadTitle + "'" + c.NewLine; ResponseChannel rc = new ResponseChannel(strScreenName, c); strResponse = rc.FetchTemplate("postnotificationbit", new object[] { not.Forum.Title, not.Thread.ThreadTitle, not.Post.PageText, not.Post.PostIndex, not.Post.DateLineText, not.Post.Username, not.Thread.ThreadID }); rc.SendMessage(strResponse); System.Threading.Thread.Sleep(2000); } else { log.WarnFormat("Could not get Connection object frop composite: {0}", not.IMNotificationInfo.InstantIMService); } } } else {// TODO: error checking } } } else { log.Info("No open connections."); } }
public void Test(CommandParser parser) { Connection c = new GTalkConnection("testuser", "testpass"); ResponseChannel rc = new ResponseChannel("aimname", c); Dictionary<string, object> d = new Dictionary<string, object>() { {"PageText","this is the pagettext"}, {"Index",8}, {"DateLineText","Today at 5pm"}, {"Username","Manchy"}, }; string str = rc.FetchTemplate(@"postbit", new object[] { "text",3,"Yesterday @ 3pm","Frank Power"} ); log.Debug(str); //VBotService.PostNotificationsResult result = BotService.Instance.GetPostNotifications(true); //UserCredentials uc = new UserCredentials(); //uc.ServiceName = @"gtalk"; //uc.Username = @"*****@*****.**"; //VBotService.PostReplyResult res = BotService.Instance.PostNewThread(uc, 2, @"title", "page text");// //UserCredentials uc1 = new UserCredentials(); //uc1.ServiceName = @"aim"; //uc1.Username = @"zethon"; //VBotService.RequestResult res = BotService.Instance.WhoAmI(uc); }