Beispiel #1
0
        private static async Task <object> BanUserHistoryAsync(TelegramBotAbstract sender, MessageEventArgs e)
        {
            var r = Owners.CheckIfOwner(e.Message.From.Id);

            if (!r)
            {
                return(r);
            }

            var query = "SELECT DISTINCT T1.target FROM " +
                        "(SELECT * FROM Banned WHERE banned_true_unbanned_false = 83 ORDER BY when_banned DESC) AS T1, " +
                        "(SELECT * FROM Banned WHERE banned_true_unbanned_false != 83 ORDER BY when_banned DESC) AS T2 " +
                        "WHERE (T1.target = T2.target AND T1.when_banned >= T2.when_banned AND T1.target IN (SELECT target FROM(SELECT target FROM Banned WHERE banned_true_unbanned_false != 83 ORDER BY when_banned DESC))) OR (T1.target NOT IN (SELECT target FROM (SELECT target FROM Banned WHERE banned_true_unbanned_false != 83 ORDER BY when_banned DESC)))";
            var x = SqLite.ExecuteSelect(query);

            if (x == null || x.Rows == null || x.Rows.Count == 0)
            {
                var text3 = new Language(new Dictionary <string, string>
                {
                    { "en", "There are no users to ban!" }
                });
                await sender.SendTextMessageAsync(e.Message.From.Id, text3, ChatType.Private,
                                                  e.Message.From.LanguageCode, ParseMode.Html, null, e.Message.From.Username, e.Message.MessageId);

                return(false);
            }

            var groups = SqLite.ExecuteSelect("Select id From Groups");

            /*
             * if(e.Message.Text.Length !=10)
             * {
             *  Language text2 = new Language(new Dictionary<string, string>() {
             *      {"en", "Group not found (1)!"}
             *  });
             *  await sender.SendTextMessageAsync(e.Message.From.Id, text2, ChatType.Private, e.Message.From.LanguageCode, ParseMode.Html, null, e.Message.From.Username, e.Message.MessageId, false);
             *  return false;
             * }
             */
            var counter = 0;
            var channel = Regex.Match(e.Message.Text, @"\d+").Value;

            if (groups.Select("id = " + "'" + channel + "'").Length != 1)
            {
                var text2 = new Language(new Dictionary <string, string>
                {
                    { "en", "Group not found! (2)" }
                });
                await sender.SendTextMessageAsync(e.Message.From.Id, text2, ChatType.Private,
                                                  e.Message.From.LanguageCode, ParseMode.Html, null, e.Message.From.Username, e.Message.MessageId);

                return(false);
            }

            foreach (DataRow element in x.Rows)
            {
                var userToBeBanned = Convert.ToInt64(element.ItemArray[0]);
                await RestrictUser.BanUserFromGroup(sender, e, userToBeBanned, Convert.ToInt64(channel), null);

                counter++;
            }

            var text = new Language(new Dictionary <string, string>
            {
                { "en", "Banned " + counter + " in group: " + groups.Select(channel) }
            });
            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(true);
        }
Beispiel #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;
            }
            }
        }