Пример #1
0
        /// <summary>
        /// This unbans the specified user in the specified chat.
        /// </summary>
        /// <param name="chatId">The Numeric Long that represents a group or channel ID. You cannot use a bot or user ID here.</param>
        /// <param name="userId">The Numeric long that represents a user or bot to unban.</param>
        /// <returns></returns>
        public static Result <bool> unbanChatMember(long chat_id, long user_id)
        {
            KickChatMemberRequest kcmr = new KickChatMemberRequest()
            {
                chat_id = chat_id,
                user_id = user_id
            };
            Result <bool> unbanResult = null;

            unbanResult = sendRequest <bool>(Method.unbanChatMember, buildRequest <KickChatMemberRequest>(kcmr));
            return(unbanResult);
        }
Пример #2
0
        //internal static Update[] getFirstUpdates(int to = 3600)
        //{
        //    GetUpdates request = new GetUpdates() { limit = 100, timeout = to };
        //
        //    Result<Update[]> result = sendRequest<Update[]>(Method.getUpdates, buildRequest<GetUpdates>(request));
        //
        //    if (result.ok)
        //    {
        //        return result.result;
        //    }
        //    else
        //    {
        //        Logger.LogError("(" + result.errorCode + ") " + result.description);
        //        return null;
        //    }
        //}

        /// <summary>
        /// This method is the same as kick, except it leaves the restriction on the user.
        /// </summary>
        /// <param name="chatId">The Numeric long that represents a group or channel ID. You cannot use a bot or user ID here.</param>
        /// <param name="userId">The Numeric long that represents a user or bot to ban.</param>
        /// <param name="untilEpoch">The Epoch date in which Telegram will automatically unban the users. Less then 30 seconds, or more than 365 days, the ban is permanent.</param>
        /// <returns></returns>
        public static Result <bool> banChatMember(long chatId, long userId, int untilEpoch = 0)
        {
            KickChatMemberRequest kcmr = new KickChatMemberRequest()
            {
                chat_id = chatId,
                user_id = userId,
            };

            if (untilEpoch < 30)
            {
                kcmr.until_date = Utilities.EpochTime() + 10;
            }
            Result <bool> result = null;

            result = sendRequest <bool>(Method.kickChatMember, buildRequest <KickChatMemberRequest>(kcmr));
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Removes the user from the specified group, then removes the ban entry.
        /// </summary>
        /// <param name="chatId">Represents a group or channel id. You cannot use a bot or user ID here.</param>
        /// <param name="userId">Represents a user or bot to kick.</param>
        /// <returns></returns>
        public static Result <bool> kickChatMember(long chatId, long userId)
        {
            KickChatMemberRequest kcmr = new KickChatMemberRequest()
            {
                chat_id = chatId,
                user_id = userId,
            };
            string        Payload     = buildRequest <KickChatMemberRequest>(kcmr);
            Result <bool> result      = null;
            Result <bool> unbanResult = null;

            result = sendRequest <bool>(Method.kickChatMember, Payload);

            if (result.ok)
            {
                unbanResult = sendRequest <bool>(Method.unbanChatMember, Payload);
            }
            else
            {
                return(result);
            }
            return(unbanResult);
        }