예제 #1
0
        private static async Task <SuccessWithException> BanUserAsync(
            TelegramBotAbstract sender, MessageEventArgs e,
            string[] stringInfo)
        {
            var r =
                await Groups.CheckIfAdminAsync(e.Message.From.Id, e.Message.From.Username, e.Message.Chat.Id, sender);

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

            if (e.Message.ReplyToMessage == null)
            {
                var userIdFound = await Info.GetTargetUserIdAsync(stringInfo[1], sender);

                if (userIdFound == null)
                {
                    var e2 = new Exception("Can't find userid (1)");
                    await NotifyUtil.NotifyOwners(new ExceptionNumbered(e2), sender);

                    return(new SuccessWithException(false, e2));
                }

                var targetId = userIdFound.GetID();
                if (targetId == null)
                {
                    var e2 = new Exception("Can't find userid (2)");
                    await NotifyUtil.NotifyOwners(new ExceptionNumbered(e2), sender);

                    return(new SuccessWithException(false, e2));
                }

                return(await RestrictUser.BanUserFromGroup(sender, e, targetId.Value, e.Message.Chat.Id, null));
            }

            var targetInt = e.Message.ReplyToMessage.From.Id;

            return(await RestrictUser.BanUserFromGroup(sender, e, targetInt, e.Message.Chat.Id, stringInfo));
        }
        private static async Task <bool> BanUserAsync(TelegramBotAbstract sender, MessageEventArgs e,
                                                      string[] stringInfo)
        {
            var r = await Groups.CheckIfAdminAsync(e.Message.From.Id, e.Message.Chat.Id, sender);

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

            if (e.Message.ReplyToMessage == null)
            {
                var targetInt = await Info.GetTargetUserIdAsync(stringInfo[1], sender);

                return(targetInt != null &&
                       await RestrictUser.BanUserFromGroup(sender, e, targetInt.Value, e.Message.Chat.Id, null));
            }
            else
            {
                var targetInt = e.Message.ReplyToMessage.From.Id;
                return(await RestrictUser.BanUserFromGroup(sender, e, targetInt, e.Message.Chat.Id, stringInfo));
            }
        }