Пример #1
0
        public override Task ProcessMessage(Message message)
        {
            User = Utils.AddOrGetUser(message.From);
            if (!CommandStart.Contains(message.Text.ToCharArray()[0]))
            {
                return(Task.CompletedTask);
            }

            return(Task.WhenAll(Commands(message)));
        }
Пример #2
0
        private async Task ProcessUpload(Message message)
        {
            ImgurModels.User ImgurUser = Utils.AddOrGetUser(message.From);

            long   chatId    = message.Chat.Id;
            int    messageId = message.MessageId;
            string fileId    = null;

            IMG.FileType fileType = IMG.FileType.Image;

            if (message.Type == TGENUMS.MessageType.Photo)
            {
                fileId = message.Photo.Last().FileId;
            }
            else if (message.Type == TGENUMS.MessageType.Document && Utils.IsMimeTypeImage(message.Document.MimeType)) /* Image send as doc */
            {
                fileId = message.Document.FileId;
            }
            else if (message.Type == TGENUMS.MessageType.Document && Utils.IsMimeTypeVideo(message.Document.MimeType)) /* GIF or Video */
            {
                fileId   = message.Document.FileId;
                fileType = IMG.FileType.Video;
            }

            if (string.IsNullOrEmpty(fileId))
            {
                await SendMessage(message.Chat.Id, "Can you send an Image?");

                return;
            }

            File tgFile = await Bot.GetFileAsync(fileId);

            if (Utils.FileSizeReached(tgFile.FileSize, fileType, out string maxFileSize))
            {
                await SendMessage(message.Chat.Id, $"Maximum file size reached! Max filesize for {fileType}: {maxFileSize}");

                return;
            }

            /* Handle File size */
            await UploadImage(ImgurUser.Id, chatId, messageId, tgFile, fileType);
        }