Ejemplo n.º 1
0
        public override async Task ExecuteAsync(Update update, Dictionary <string, string> parsedMessage)
        {
            if (!DwellerBot.IsUserOwner(update.Message.From))
            {
                return;
            }

            _dwellerBot.CommandService.SaveCommandStates();

            await Bot.SendTextMessageAsync(update.Message.Chat.Id, "State saved.", Telegram.Bot.Types.Enums.ParseMode.Markdown, false, false, update.Message.MessageId);
        }
Ejemplo n.º 2
0
        async Task IgnoreLastSubCommand(Message message)
        {
            if (DwellerBot.IsUserOwner(message.From))
            {
                if (!string.IsNullOrEmpty(_lastUsedFile))
                {
                    var relativePath = GetRelativePath(_lastUsedFile);
                    if (_sentFiles.ContainsKey(relativePath))
                    {
                        _sentFiles.Remove(relativePath);
                    }
                    else
                    {
                        Log.Logger.Debug("_lastUsedFile is not null, but is absent from _sentFiles!");
                    }

                    // TODO: Remove last used from uploaded files

                    if (!_ignoredFiles.Contains(relativePath))
                    {
                        _ignoredFiles.Add(relativePath);
                    }
                    else
                    {
                        Log.Logger.Debug("Last file was already in the _ignoredFiles.");
                    }

                    if (_files.Any(f => f.FullName == _lastUsedFile))
                    {
                        var file = _files.First(f => f.FullName == _lastUsedFile);
                        _files.Remove(file);
                    }
                    else
                    {
                        Log.Logger.Debug("Last file was not present in _files.");
                    }

                    _lastUsedFile = null;
                    await Bot.SendTextMessageAsync(message.Chat.Id, "Last sent file has been added to ignored files.", ParseMode.Markdown, false, false, message.MessageId);

                    return;
                }
            }
            else
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, "Only the bot owner can use this command.", ParseMode.Markdown, false, false, message.MessageId);
            }
        }
Ejemplo n.º 3
0
        public override async Task HandleMessageAsync(Message message, Dictionary <string, string> parsedMessage)
        {
            if (!DwellerBot.IsUserOwner(message.From))
            {
                return;
            }

            if (_dwellerBot.CommandService.RegisteredCommands.TryGetValue("/savestate", out ICommand command))
            {
                await command.HandleMessageAsync(message, parsedMessage);
            }

            await Bot.SendTextMessageAsync(message.Chat.Id, "Shutting down.", Telegram.Bot.Types.Enums.ParseMode.Markdown, false, false, message.MessageId);

            _dwellerBot.CancellationTokenSource.CancelAfter(100);
        }
Ejemplo n.º 4
0
        public override async Task ExecuteAsync(Update update, Dictionary <string, string> parsedMessage)
        {
            if (!DwellerBot.IsUserOwner(update.Message.From))
            {
                return;
            }

            ICommand command;

            if (_dwellerBot.CommandService.RegisteredCommands.TryGetValue("/savestate", out command))
            {
                await command.ExecuteAsync(update, parsedMessage);
            }

            _dwellerBot.IsOnline = false;

            await Bot.SendTextMessageAsync(update.Message.Chat.Id, "Shutting down.", Telegram.Bot.Types.Enums.ParseMode.Markdown, false, false, update.Message.MessageId);

            await Bot.GetUpdatesAsync(update.Id + 1);
        }
Ejemplo n.º 5
0
 public SaveStateCommand(Api bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 6
0
 public ShutdownCommand(TelegramBotClient bot, DwellerBot dwellerBot) : base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 7
0
 public SaveStateCommand(TelegramBotClient bot, DwellerBot dwellerBot) : base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 8
0
 public DebugCommand(Api bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 9
0
 public DebugCommand(TelegramBotClient bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 10
0
        public override async Task HandleMessageAsync(Message message, Dictionary <string, string> parsedMessage)
        {
            if (parsedMessage.ContainsKey("message"))
            {
                var args = parsedMessage["message"].Split(',');
                if (args.Length == 1)
                {
                    // List all opened or done features
                    if (args[0].Equals("list") || args[0].Equals("done") || args[0].Equals("all"))
                    {
                        bool   listOpened = args[0].Equals("list") || args[0].Equals("all");
                        string result     = "";
                        foreach (var pair in _requests)
                        {
                            if (listOpened && pair.Value.IndexOf("[Done]") == 0)
                            {
                                continue;
                            }
                            if (!listOpened && pair.Value.IndexOf("[Done]") != 0)
                            {
                                continue;
                            }
                            result += string.Format("{0}: {1}{2}", pair.Key, pair.Value, Environment.NewLine);
                        }

                        await Bot.SendTextMessageAsync(message.Chat.Id, result, Telegram.Bot.Types.Enums.ParseMode.Default, false, false, message.MessageId);

                        return;
                    }
                }
                else if (args.Length == 2)
                {
                    int index;
                    if (args[0].Equals("close") && int.TryParse(args[1], out index) && _requests.ContainsKey(index) && DwellerBot.IsUserOwner(message.From))
                    {
                        _requests[index] = "[Done] " + _requests[index];
                        var result = string.Format("{0}: {1}{2}", index, _requests[index], Environment.NewLine);
                        await Bot.SendTextMessageAsync(message.Chat.Id, result, Telegram.Bot.Types.Enums.ParseMode.Default, false, false, message.MessageId);

                        return;
                    }
                }

                _requests.Add(_requestIndex, string.Format("{0} asked for: {1}", message.From.FirstName, parsedMessage["message"]));
                _requestIndex++;

                await Bot.SendTextMessageAsync(message.Chat.Id, string.Format("A request has been added under #{0}", _requestIndex - 1), Telegram.Bot.Types.Enums.ParseMode.Markdown, false, false, message.MessageId);

                return;
            }

            await Bot.SendTextMessageAsync(message.Chat.Id, "You have to describe your request :)\nlist - opened requests\ndone - completed requests", Telegram.Bot.Types.Enums.ParseMode.Markdown, false, false, message.MessageId);
        }
Ejemplo n.º 11
0
 public DebugCommand(TelegramBotClient bot, DwellerBot dwellerBot) : base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 12
0
 public ShutdownCommand(Api bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 13
0
 public ShutdownCommand(TelegramBotClient bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }
Ejemplo n.º 14
0
 public SaveStateCommand(TelegramBotClient bot, DwellerBot dwellerBot):base(bot)
 {
     _dwellerBot = dwellerBot;
 }