public static async Task CommandDispatcherMethod(TelegramBotAbstract sender, MessageEventArgs e)
        {
            var cmdLines = e.Message.Text.Split(' ');
            var cmd      = cmdLines[0];

            switch (cmd)
            {
            case "/start":
            {
                await Start(sender, e);

                return;
            }

            case "/force_check_invite_links":
            {
                if (GlobalVariables.Creators.Contains(e.Message.Chat.Id))
                {
                    _ = ForceCheckInviteLinksAsync(sender, e);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/contact":
            {
                await ContactUs(sender, e);

                return;
            }

            case "/help":
            {
                await Help(sender, e);

                return;
            }

            case "/banAll":
            {
                if (GlobalVariables.Creators.Contains(e.Message.From.Id))
                {
                    _ = BanAllAsync(sender, e, cmdLines, e.Message.From.LanguageCode, e.Message.From.Username);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/ban":
            {
                _ = BanUserAsync(sender, e, cmdLines);
                return;
            }

            case "/unbanAll":
            {
                if (GlobalVariables.Creators.Contains(e.Message.From.Id))
                {
                    _ = UnbanAllAsync(sender, e, cmdLines[1]);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/getGroups":
            {
                if (GlobalVariables.Creators.Contains(e.Message.From.Id) && e.Message.Chat.Type == ChatType.Private)
                {
                    string username = null;
                    if (!string.IsNullOrEmpty(e.Message.From.Username))
                    {
                        username = e.Message.From.Username;
                    }
                    _ = GetAllGroups(e.Message.From.Id, username, sender, e.Message.From.LanguageCode);
                    return;
                }

                await DefaultCommand(sender, e);

                return;
            }

            case "/time":
            {
                var lang = new Language(new Dictionary <string, string>
                    {
                        { "", DateTimeClass.NowAsStringAmericanFormat() }
                    });
                await SendMessage.SendMessageInPrivate(sender, e, lang);

                return;
            }

            case "/assoc_send":
            {
                _ = Assoc.Assoc_SendAsync(sender, e);
                return;
            }

            default:
            {
                await DefaultCommand(sender, e);

                return;
            }
            }
        }
Exemplo n.º 2
0
        public static async Task CommandDispatcherMethod(TelegramBotAbstract sender, MessageEventArgs e)
        {
            var cmdLines = e.Message.Text.Split(' ');
            var cmd      = cmdLines[0].Trim();

            if (cmd.Contains("@"))
            {
                var cmd2        = cmd.Split("@");
                var botUsername = await sender.GetBotUsernameAsync();

                if (cmd2[1].ToLower() != botUsername.ToLower())
                {
                    return;
                }
            }

            switch (cmd)
            {
            case "/start":
            {
                await Start(sender, e);

                return;
            }

            case "/force_check_invite_links":
            {
                if (GlobalVariables.Creators.Contains(e.Message?.Chat?.Username?.ToLower()))
                {
                    _ = ForceCheckInviteLinksAsync(sender, e);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/contact":
            {
                await ContactUs(sender, e);

                return;
            }

            case "/help":
            {
                await Help(sender, e);

                return;
            }

            case "/muteAll":
            {
                if (e.Message.Chat.Type != ChatType.Private)
                {
                    await CommandNotSentInPrivateAsync(sender, e);

                    return;
                }

                if (GlobalVariables.AllowedMuteAll.Contains(e.Message.From?.Username?.ToLower()))
                {
                    _ = MuteAllAsync(sender, e, cmdLines, e.Message.From.LanguageCode, e.Message.From.Username);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/banAll":
            {
                if (e.Message.Chat.Type != ChatType.Private)
                {
                    await CommandNotSentInPrivateAsync(sender, e);

                    return;
                }

                if (GlobalVariables.AllowedBanAll.Contains(e.Message.From?.Username?.ToLower()))
                {
                    _ = BanAllAsync(sender, e, cmdLines, e.Message.From.LanguageCode, e.Message.From.Username);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            /*
             * case "/massiveSend":
             * {
             *  if (e.Message.Chat.Type != ChatType.Private)
             *  {
             *      await CommandNotSentInPrivateAsync(sender, e);
             *      return;
             *  }
             *
             *  try
             *  {
             *      if (GlobalVariables.AllowedBanAll.Contains(e.Message.From?.Username?.ToLower()))
             *          _ = MassiveSendAsync(sender, e, cmdLines, e.Message.From.LanguageCode, e.Message.From.Username);
             *      else
             *          await DefaultCommand(sender, e);
             *  }
             *  catch
             *  {
             *      ;
             *  }
             *
             *  return;
             * }
             */

            case "/ban":
            {
                _ = BanUserAsync(sender, e, cmdLines);
                return;
            }

            case "/banAllHistory":
            {
                // _ = BanUserAsync(sender, e, cmdLines);
                _ = BanUserHistoryAsync(sender, e);
                return;
            }

            case "/unbanAll":
            {
                if (e.Message.Chat.Type != ChatType.Private)
                {
                    await CommandNotSentInPrivateAsync(sender, e);

                    return;
                }

                if (GlobalVariables.AllowedBanAll.Contains(e.Message.From?.Username?.ToLower()))
                {
                    _ = UnbanAllAsync(sender, e, cmdLines, e.Message.From.LanguageCode, e.Message.From.Username);
                }
                else
                {
                    await DefaultCommand(sender, e);
                }
                return;
            }

            case "/test_spam":
            {
                if (e.Message == null)
                {
                    return;
                }
                if (e.Message.ReplyToMessage == null)
                {
                    return;
                }

                await TestSpamAsync(e.Message.ReplyToMessage, sender, e);

                return;
            }

            case "/groups":
            {
                await SendRecommendedGroupsAsync(sender, e);

                return;
            }

            case "/getGroups":
            {
                if ((GlobalVariables.Creators.Contains(e.Message.From.Username) ||
                     Owners.CheckIfOwner(e.Message.From.Id)) &&
                    e.Message.Chat.Type == ChatType.Private)
                {
                    string username = null;
                    if (!string.IsNullOrEmpty(e.Message.From.Username))
                    {
                        username = e.Message.From.Username;
                    }

                    _ = GetAllGroups(e.Message.From.Id, username, sender, e.Message.From.LanguageCode);
                    return;
                }

                await DefaultCommand(sender, e);

                return;
            }

            case "/allowmessage":
            {
                if ((Owners.CheckIfOwner(e.Message.From.Id)) &&
                    e.Message.Chat.Type == ChatType.Private)
                {
                    if (e.Message.ReplyToMessage == null || string.IsNullOrEmpty(e.Message.ReplyToMessage.Text))
                    {
                        var text = new Language(new Dictionary <string, string>
                            {
                                { "en", "You have to reply to a message containing the message" }
                            });
                        await sender.SendTextMessageAsync(e.Message.From.Id, text, ChatType.Private,
                                                          e.Message.From.LanguageCode, ParseMode.Html, null, e.Message.From.Username,
                                                          e.Message.MessageId);

                        return;
                    }

                    AllowedMessages.AddMessage(e.Message.ReplyToMessage.Text);
                    return;
                }

                await DefaultCommand(sender, e);

                return;
            }

            case "/unallowmessage":
            {
                if ((Owners.CheckIfOwner(e.Message.From.Id)) &&
                    e.Message.Chat.Type == ChatType.Private)
                {
                    if (e.Message.ReplyToMessage == null || string.IsNullOrEmpty(e.Message.ReplyToMessage.Text))
                    {
                        var text = new Language(new Dictionary <string, string>
                            {
                                { "en", "You have to reply to a message containing the message" }
                            });
                        await sender.SendTextMessageAsync(e.Message.From.Id, text, ChatType.Private,
                                                          e.Message.From.LanguageCode, ParseMode.Html, null, e.Message.From.Username,
                                                          e.Message.MessageId);

                        return;
                    }

                    AllowedMessages.removeMessage(e.Message.ReplyToMessage.Text);
                    return;
                }

                await DefaultCommand(sender, e);

                return;
            }

            case "/updateGroups":
            {
                if ((GlobalVariables.Creators.Contains(e.Message.From.Username) ||
                     Owners.CheckIfOwner(e.Message.From.Id)) &&
                    e.Message.Chat.Type == ChatType.Private)
                {
                    //System.Data.DataTable groups = Groups.GetAllGroups();
                    //var jsonFile = JObject.Parse(groups.ToString());
                    if (Variabili.L == null)
                    {
                        Variabili.L = new ListaGruppo();
                    }

                    Variabili.L.ImportaGruppiDaTabellaTelegramGruppiBot_PuntoBin();

                    var json =
                        JsonBuilder.getJson(new CheckGruppo(CheckGruppo.E.RICERCA_SITO_V3),
                                            false);
                }

                await DefaultCommand(sender, e);

                return;
            }

            case "/testtime":
            {
                if (e.Message.Chat.Type == ChatType.Private)
                {
                    await TestTime(sender, e);
                }

                return;
            }

            case "/time":
            {
                var lang = new Language(new Dictionary <string, string>
                    {
                        { "", DateTimeClass.NowAsStringAmericanFormat() }
                    });
                await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id,
                                                       usernameToSendTo : e.Message.From.Username, langCode : e.Message.From.LanguageCode,
                                                       text : lang, parseMode : ParseMode.Default, messageIdToReplyTo : null);

                return;
            }

            case "/assoc_write":
            case "/assoc_send":
            {
                _ = await Assoc.Assoc_SendAsync(sender, e);

                return;
            }

            case "/assoc_publish":
            {
                if (Owners.CheckIfOwner(e.Message.From.Id))
                {
                    _ = await Assoc.Assoc_Publish(sender, e);
                }
                else
                {
                    _ = await DefaultCommand(sender, e);
                }
                return;
            }

            case "/assoc_read":
            {
                _ = await Assoc.Assoc_Read(sender, e, false);

                return;
            }

            case "/assoc_read_all":
            {
                if (Owners.CheckIfOwner(e.Message.From.Id))
                {
                    _ = await Assoc.Assoc_ReadAll(sender, e);
                }
                else
                {
                    _ = await DefaultCommand(sender, e);
                }
                return;
            }

            case "/assoc_delete":
            case "/assoc_remove":
            {
                _ = await Assoc.Assoc_Delete(sender, e);

                return;
            }

            case "/rooms":
            {
                await Rooms.RoomsMainAsync(sender, e);

                return;
            }

            case "/rules":
            {
                _ = await Rules(sender, e);

                return;
            }

            case "/qe":
            {
                _ = await QueryBot(true, e, sender);

                return;
            }

            case "/qs":
            {
                _ = await QueryBot(false, e, sender);

                return;
            }

            case "/update_links_from_json":
            {
                await InviteLinks.UpdateLinksFromJsonAsync(sender, e);

                return;
            }

            default:
            {
                await DefaultCommand(sender, e);

                return;
            }
            }
        }