/// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="user"></param>
        public override async void Execute(Message message, UserTable user)
        {
            if (user == null)
            {
                return;
            }

            try
            {
                var result = await PassAuthentication(message, user);

                UpdateUserAndSendSuccess(message, user, result);
            }
            catch (ApiException exception)
            {
                await BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);

                await BotClient.SendTextMessageAsync(message.Chat.Id, $"{exception.Content}");

                await BotClient.SendTextMessageAsync(message.Chat.Id, "Enter Username");

                user.Command = nameof(SetUserNameCommand);
                UserRepository.UpdateUser(user);
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="callbackQuery"></param>
        /// <param name="user"></param>
        public override async void CallBackExecute(CallbackQuery callbackQuery, UserTable user)
        {
            if (user == null)
            {
                return;
            }

            try
            {
                var res = await GetUsers(user.Token);

                foreach (var userInfo in res)
                {
                    await BotClient.SendTextMessageAsync(callbackQuery.Message.Chat.Id, $"Username: {userInfo.UserName} \nPhone: {userInfo.Phone}");
                }
            }
            catch (ApiException ex)
            {
                await BotClient.DeleteMessageAsync(callbackQuery.Message.Chat.Id, callbackQuery.Message.MessageId);

                await BotClient.SendTextMessageAsync(callbackQuery.Message.Chat.Id, $"{ex.Content}  \n Message:{ex.Message}");

                return;
            }
        }
Ejemplo n.º 3
0
        private static async void ExecuteTask(ScheduleData data)
        {
            _log.Debug("Eksekusi schedule: {0}", data.MessageId);

            switch (data.Operation)
            {
            case ScheduleData.Type.Delete:
                await BotClient.DeleteMessageAsync(data.ChatId, data.MessageId);

                break;

            case ScheduleData.Type.Edit:
                await BotClient.EditOrSendTextAsync(data.ChatId, data.MessageId, data.Text, data.ParseMode,
                                                    sendOnError : false);

                break;

            case ScheduleData.Type.Done:
                return;

            default:
                return;
            }

            data.Operation = ScheduleData.Type.Done;
            await _db.InsertOrReplaceSchedule(data);
        }
Ejemplo n.º 4
0
 /// <summary>Use this method to delete a message, including service messages, with the following limitations: <br/>
 /// - A message can only be deleted if it was sent less than 48 hours ago.<br/>
 /// - Bots can delete outgoing messages in private chats, groups, and supergroups.<br/>
 /// - Bots can delete incoming messages in private chats.<br/>
 /// - Bots granted can_post_messages permissions can delete outgoing messages in channels.<br/>
 /// - If the bot is an administrator of a group, it can delete any message there.<br/>
 /// - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.<br/></summary>
 /// <param name="api"><see cref="BotClient"/> instance.</param>
 /// <param name="message">Message to delete.</param>
 /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
 /// <returns>True on success.</returns>
 /// <exception cref="BotRequestException">Thrown when a request to Telegram Bot API got an error response.</exception>
 /// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
 public static async Task <bool> DeleteMessagesAsync(this BotClient api, Message message, [Optional] CancellationToken cancellationToken)
 {
     if (api == null)
     {
         throw new ArgumentNullException(nameof(api));
     }
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     return(await api.DeleteMessageAsync(message.Chat.Id, message.MessageId, cancellationToken).ConfigureAwait(false));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="user"></param>
        /// <param name="result"></param>
        private void UpdateUserAndSendSuccess(Message message, UserTable user, AuthenticateResult result)
        {
            user.Command = null;
            user.Token   = result.Token;
            UserRepository.UpdateUser(user);

            BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
            BotClient.SendTextMessageAsync(message.Chat.Id, "Congritulations to have passed the authentication!");

            var menuCommand = new MenuCommand();

            menuCommand.Execute(message, user);
        }
Ejemplo n.º 6
0
        public async void GetMedia(string data)
        {
            if (!_message.IsPrivateChat())
            {
                return;
            }

            if (_twitter == null)
            {
                await BotClient.SendTextAsync(_message,
                                              "Tolong, bilang ke admin paijem suruh isi auth token twitter. Terima kasih");

                return;
            }

            var regex = Regex.Match(data, @"twitter.com\/.*status\/([0-9]+)");

            if (!regex.Success)
            {
                return;
            }

            ulong.TryParse(regex.Groups[1].Value, out ulong statusId);

            _log.Debug("Found twitter id : {0}", statusId);

            _message = await BotClient.SendTextAsync(_message, "Tunggu sebentar...", true);

            var status = await _twitter.Status
                         .Where(x => x.ID == statusId && x.Type == StatusType.Show && x.TweetMode == TweetMode.Extended)
                         .SingleOrDefaultAsync();

            var foundVideo = false;

            foreach (var media in status?.ExtendedEntities?.MediaEntities)
            {
                if (media.Type != "video")
                {
                    continue;
                }

                foundVideo = true;
                var video = media.VideoInfo?.Variants
                            .Where(x => x.ContentType == "video/mp4")
                            .OrderByDescending(x => x.BitRate)
                            .First();

                _log.Debug("Found video : {0}", video.Url);

                await BotClient.SendVideoAsync(_message, video.Url, media.MediaUrlHttps, status.FullText);
            }

            if (foundVideo)
            {
                await BotClient.DeleteMessageAsync(_message.Chat.Id, _message.MessageId);
            }
            else
            {
                await BotClient.EditOrSendTextAsync(_message, _message.MessageId, "Gak ada videonya!");
            }
        }
Ejemplo n.º 7
0
        private async void AsyncBotAnalize(System.Object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            DataBase db = Singleton.GetInstance().Context;

            //BotClient.SendPhotoAsync(e.Message.From.Id, e.Message.Photo[2].FileId);

            if (e.Message.From.Username != null)
            {
                SetUserName(e.Message, db);
            }


            if (IsSystemEvent(e.Message))
            {
                try
                {
                    await BotClient.DeleteMessageAsync(e.Message.Chat.Id, e.Message.MessageId);

                    return;
                }
                catch { }
            }
            if (e.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup)
            {
                if (e.Message.ReplyToMessage != null)
                {
                    if (e.Message.ReplyToMessage.MessageId != 0 && e.Message.Text != null)
                    {
                        if (IsUserAdmin(e.Message.From, e.Message.Chat))
                        {
                            if (SleshComands.Any(c => e.Message.Text.ToLower().Contains(c.Name)))
                            {
                                SleshComands.First(c => e.Message.Text.ToLower().Contains(c.Name)).Execute(BotClient, e.Message);
                                return;
                            }
                        }
                    }
                }
            }

            if (e.Message.Text != null && e.Message.Chat.Type == ChatType.Private)
            {
                User user = db.GetUser(e.Message.From.Id);

                if ((user == null || user.FIO == null || user.Number == "0") && e.Message.Text != "/start")
                {
                    try
                    {
                        new Start().Execute(BotClient, e.Message);
                        BotClient.DeleteMessage(user.ID, e.Message.MessageId, "Bot");
                    }
                    catch (Exception exception)
                    {
                        Log.Logging(exception);
                    }
                }
            }

            if (e.Message.Text != null || e.Message.Contact != null || e.Message.ForwardFromChat != null ||
                e.Message.NewChatMembers != null || e.Message.Sticker != null || e.Message.Photo != null || e.Message.MediaGroupId != null ||
                e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Voice || e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video ||
                e.Message.Type == Telegram.Bot.Types.Enums.MessageType.VideoNote || e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document ||
                e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Game || e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location ||
                e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact || e.Message.Type == Telegram.Bot.Types.Enums.MessageType.MessagePinned)
            {
                if (commands.Any(c => c.Equals(e.Message.Text)))                 // проверка есть ли команда в списке
                {
                    try
                    {
                        commands.FirstOrDefault(c => c.Equals(e.Message.Text)).Execute(BotClient, e.Message);                         // вытягиваем класс
                    }
                    catch (System.Exception ex)
                    {
                        Log.Logging(ex);
                    }
                }
                else if (commandSlashes.Any(c => c.Equals(e.Message.Text)))
                {
                    try
                    {
                        commandSlashes.FirstOrDefault(c => c.Equals(e.Message.Text)).Execute(BotClient, e.Message);                         // вытягиваем класс
                    }
                    catch (System.Exception ex)
                    {
                        Log.Logging(ex);
                    }
                }
                else if (e.Message.Text == null || e.Message.Sticker != null || e.Message.Photo != null || e.Message.MediaGroupId != null)
                {
                    Analize t = new Analize();
                    t.ChekRegister(BotClient, e.Message);
                }
                else if (!e.Message.Text.Equals("/start"))
                {
                    Analize t = new Analize();
                    t.ChekRegister(BotClient, e.Message);
                }
            }
        }
Ejemplo n.º 8
0
        private void BotClient_OnMessage(object sender, MessageEventArgs e)
        {
            Message message = e ? .Message;

            if (message != null &&
                message.Type == MessageType.Text)
            {
                Stopwatch stopwatch = new Stopwatch( );

                stopwatch.Start( );

                List <MarkedValue <string, int> > emojiList =
                    new List <MarkedValue <string, int> > (
                        EmojiList.Select(
                            emoj => new MarkedValue <string, int> (emoj.Value, emoj.Mark)));
                string text  = e.Message.Text.Normalize(NormalizationForm.FormD);
                int    lenth = text.Length;

                int emojiLenth    = 0;
                int nonEmojiLenth = 0;
                int spaceCount    = 0;

                while (emojiLenth + nonEmojiLenth < lenth)
                {
                    MarkedValue <string, int> emoji =
                        emojiList.FirstOrDefault(emoj =>
                                                 text.StartsWith(emoj, StringComparison.Ordinal));

                    if (emoji != null)
                    {
                        emojiLenth += emoji.Value.Length;
                        emoji.Mark++;
                        text = text.Substring(emoji.Value.Length);
                    }
                    else
                    {
                        if (char.GetUnicodeCategory(text.First( )) == UnicodeCategory.SpaceSeparator)
                        {
                            spaceCount++;
                        }

                        nonEmojiLenth++;
                        text = text.Substring(1);
                    }
                }

                int usedEmojiTypeCount = 0;

                int amountOfEmoji = 0;

                foreach (MarkedValue <string, int> emoji in emojiList)
                {
                    if (emoji.Mark > 0)
                    {
                        usedEmojiTypeCount++;
                        amountOfEmoji += emoji.Mark;
                    }
                }

                stopwatch.Stop( );


                if (e.Message.Chat.Type == ChatType.Private)
                {
                    BotClient.SendTextMessageAsync(message.Chat.Id,
                                                   $"TextLenth:{lenth}" + Environment.NewLine +
                                                   $"EmojiLenth:{emojiLenth}" + Environment.NewLine +
                                                   $"EmojiCount:{amountOfEmoji}" + Environment.NewLine +
                                                   $"EmojiKind:{usedEmojiTypeCount}" + Environment.NewLine +
                                                   $"Cost:{stopwatch . Elapsed}",
                                                   replyToMessageId: message.MessageId);
                }
                else if (e.Message.Chat.Type == ChatType.Group ||
                         e.Message.Chat.Type == ChatType.Supergroup)
                {
                    if (usedEmojiTypeCount >= 2)                       //((emojiLenth * 2)+spaceCount) >= lenth &&

                    {
                        BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
                    }
                }
            }
        }