コード例 #1
0
        /// <summary>
        /// Fügt einen neuen Subscriber hinzu
        /// </summary>
        /// <param name="chatId">Chat ID des hinzuzufügenden chats</param>
        public static async Task AddSubscriber(Types.ChatId chatId)
        {
            ChatIDs.Add(chatId);

            await WriteSubscribersToFile();
        }
コード例 #2
0
        /// <summary>
        /// Entfernt einen Subscriber von der Liste
        /// </summary>
        /// <param name="chatId">Chat ID des zu entfernenden Chats</param>
        public static async Task RemoveSubscriber(Types.ChatId chatId)
        {
            ChatIDs.Remove(chatId);

            await WriteSubscribersToFile();
        }
コード例 #3
0
ファイル: frmMain.cs プロジェクト: ShayestehHS/BotManager
        private void runBot()
        {
            Bot = new Telegram.Bot.TelegramBotClient(Token);

            this.Invoke(new Action(() =>
            {
                lblStatus.Text      = "Online";
                lblStatus.ForeColor = Color.Green;
            }));
            int offset = 0;

            while (true)
            {
                try
                {
                    Telegram.Bot.Types.Update[] Update = Bot.GetUpdatesAsync(offset).Result;

                    foreach (Telegram.Bot.Types.Update Up in Update)
                    {
                        offset = Up.Id + 1;
                        while (Up.CallbackQuery != null)
                        {
                            //Contatct To Me Inline
                            if (Up.CallbackQuery.Data.Contains("gmail"))
                            {
                                Bot.SendTextMessageAsync(Up.CallbackQuery.Message.Chat.Id, "My Gmail address is : [email protected]"); Up.CallbackQuery = null; break;
                            }
                            else if (Up.CallbackQuery.Data.Contains("outlook"))
                            {
                                Bot.SendTextMessageAsync(Up.CallbackQuery.Message.Chat.Id, "My Outlook address is : [email protected]"); Up.CallbackQuery = null; break;
                            }
                            //Poll Inline
                            var user = db.PollManager.SingleOrDefault(u => u.UserID == Up.CallbackQuery.From.Id);
                            if (user == null)
                            {
                                user = new PollManager()
                                {
                                    UserID      = Up.CallbackQuery.From.Id,
                                    VotedByUser = ""
                                };
                                db.PollManager.Add(user);
                                db.SaveChanges();
                            }
                            var UserID       = Up.CallbackQuery.From.Id;
                            var pUserID      = db.PollManager.Select(p => p.UserID).ToList();
                            var pVotedByUSer = db.PollManager.Select(p => p.VotedByUser).ToList();
                            var query        = Up.CallbackQuery.Data;

                            string VotedNow = Up.CallbackQuery.Data;
                            if (db.PollManager.Any(p => (p.UserID == Up.CallbackQuery.From.Id) && (p.VotedByUser != VotedNow)))
                            {
                                Poll(Up, db.PollManager.SingleOrDefault(a => a.UserID == UserID).VotedByUser, VotedNow);

                                InlineKeyboardMarkup PollButons = PollInline();
                                Bot.EditMessageReplyMarkupAsync(Up.CallbackQuery.Message.Chat.Id, Up.CallbackQuery.Message.MessageId, replyMarkup: PollButons);
                                Up.CallbackQuery = null;
                            }
                            else
                            {
                                Bot.SendTextMessageAsync(Up.CallbackQuery.Message.Chat.Id, "You have rated before");
                            }
                            Up.CallbackQuery = null;
                        }


                        if (Up.Message == null)
                        {
                            continue;
                        }

                        string MessageFromUser           = Up.Message.Text.ToLower();
                        Telegram.Bot.Types.User   Upfrom = Up.Message.From;
                        Telegram.Bot.Types.ChatId ChatID = Up.Message.Chat.Id;

                        StringBuilder SB = new StringBuilder();
                        if (MessageFromUser.Contains("start"))
                        {
                            ReplyKeyboardMarkup MainKeyboardMarkup = StartKeyboards();
                            SB.AppendLine("Welcome To My Bot");
                            SB.AppendLine("Contact To Me : /ContactToMe");
                            SB.AppendLine("About Me : /AboutMe");
                            Bot.SendTextMessageAsync(ChatID, SB.ToString(), parseMode: default, false, true, 0, MainKeyboardMarkup);