public async Task OnBotCommand(BotCommandEventArgs e) { if (this.BotCommand != null) { await BotCommand(this, e); } }
private void UserPopChannelRequest(BotCommandEventArgs obj) { //No parameters, for now try { Models.StoredChannels firstStoredChannel; List <Models.StoredChannels> allChannelsUnderSameSubscriber; using (var db = new CoreContext()) { allChannelsUnderSameSubscriber = db.StoredChannels.Where(x => x.SubscriberId == this.Subscriber.SubscriberId).ToList(); firstStoredChannel = allChannelsUnderSameSubscriber.First(x => x.ChannelId == 52); } if (firstStoredChannel.ParentChannelId != 0) { var parent = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)firstStoredChannel.ParentChannelId); if (parent.IsErroneous) { throw new Exception("Parent channel no longer exists"); } } Props.ChannelWithSubChannelsPackager ChannelWithSubChannels = new Props.ChannelWithSubChannelsPackager(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); ChannelWithSubChannels.Pop(allChannelsUnderSameSubscriber, firstStoredChannel, PopChannel); //PopChannel((int)firstStoredChannel.ChannelId); } catch (Exception ex) { logger.Warn(ex, "Failed to pop channel by user {1} ({2})", obj.MessageInfo.InvokerClientId, obj.MessageInfo.InvokerNickname); } }
private void UserSortRequest(BotCommandEventArgs obj) { //No parameters, just need to call sort and assume the channel the user is in. var clientInfo = ServerQueryConnection.QueryRunner.GetClientInfo(obj.MessageInfo.InvokerClientId); SortSubChannels((int)clientInfo.ChannelId); }
private void UserStoreChannelRequest(BotCommandEventArgs obj) { //No parameters, just need to store on the channel the user is in (for now). try { var clientInfo = ServerQueryConnection.QueryRunner.GetClientInfo(obj.MessageInfo.InvokerClientId); StoreChannel((int)clientInfo.ChannelId); } catch (Exception ex) { logger.Warn(ex, "Failed to store channel by user {1} ({2})", obj.MessageInfo.InvokerClientId, obj.MessageInfo.InvokerNickname); } }
public void Test(BotCommandEventArgs e) { }
public void ServerQueryUserRegistrationCommand(BotCommandEventArgs e) { using (var db = new CoreContext()) { var user = UserManager.QueryUser(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, e.MessageInfo.InvokerUniqueId); Models.ServerQueryUser sqUser = new Models.ServerQueryUser() { UserId = user.UserId, Users = user, //SubscriberId = user.SubscriberId, ServerQueryUsername = e.CommandInfo["username"].Value, ServerQueryPassword = e.CommandInfo["password"].Value, }; Lyralei.Core.ServerQueryConnection.Models.Subscribers subscriberUserCredentials = new Lyralei.Core.ServerQueryConnection.Models.Subscribers() { AdminPassword = sqUser.ServerQueryPassword, AdminUsername = sqUser.ServerQueryUsername, ServerIp = Subscriber.ServerIp, ServerPort = Subscriber.ServerPort, SubscriberId = Subscriber.SubscriberId, SubscriberUniqueId = Subscriber.SubscriberUniqueId, VirtualServerId = Subscriber.VirtualServerId, }; Core.ServerQueryConnection.ServerQueryConnection ServerQueryConnection = new Core.ServerQueryConnection.ServerQueryConnection(subscriberUserCredentials); Thread thread = new Thread((ThreadStart) new SynchronizationCallback(ServerQueryConnection.InitializeQuiet)); thread.Start(); thread.Join(); try { if (ServerQueryConnection.AsyncTcpDispatcher.IsConnected) { var test = ServerQueryConnection.whoAmI; if (test == null) { throw new Exception("Login failure"); } if (test.IsErroneous) { throw new Exception(test.ResponseText); } else { db.ServerQueryUser.Add(sqUser); db.SaveChanges(); ServerQueryConnection.Logout(); ServerQueryConnection.Disconnect(); //User successfully registered ServerQueryConnection.TextReply(e.MessageInfo, "Successfully registered! You can now execute serverquery commands directly to me based on your user permissions."); } } } catch (Exception ex) { logger.Debug(ex, "User failed to register"); ServerQueryConnection.TextReply(e.MessageInfo, "Whoops! Did you put in the right details?"); } } }
private async Task Client_TryMessage(object sender, MessageResult e) { DeviceSession ds = e.Device; if (ds == null) { ds = await this.Sessions.StartSession <T>(e.DeviceId); e.Device = ds; ds.LastMessage = e.Message; OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); } ds.LastAction = DateTime.Now; ds.LastMessage = e.Message; //Is this a bot command ? if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) { var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); await OnBotCommand(sce); if (sce.Handled) { return; } } FormBase activeForm = null; int i = 0; //Should formulars get navigated (allow maximum of 10, to dont get loops) do { i++; //Reset navigation ds.FormSwitched = false; activeForm = ds.ActiveForm; //Pre Loading Event await activeForm.PreLoad(e); //Send Load event to controls await activeForm.LoadControls(e); //Loading Event await activeForm.Load(e); //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Photo | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Audio) { await activeForm.SentData(new DataResult(e)); } //Render Event if (!ds.FormSwitched) { await activeForm.RenderControls(e); await activeForm.Render(e); } e.IsFirstHandler = false; } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); }