Example #1
0
        public async Task <bool> Process(ITelegramBotClient botClient, Update update, NeededItems n)
        {
            if (n.Sender.Id == botClient.BotId)
            {
                await botClient.SendTextMessageAsync(n.ChatId, $"HI there ...");

                var c = new GroupServices();

                if (!await c.CheckByTlId(n.ChatId))
                {
                    await c.Create(new Models.BaseModels.Group
                    {
                        About          = "",
                        OwnerId        = 0,
                        TelegramId     = n.ChatId,
                        Title          = update.Message.Chat.Title,
                        WelcomeMessage = ""
                    });
                }
            }
            else
            {
                if (n.Sender.IsBot)
                {
                    return(true);
                }

                var c = new GroupServices();

                if (await c.CheckByTlId(n.ChatId))
                {
                    var wlc = await c.WlcmsgByTlId(n.ChatId).ConfigureAwait(false);

                    if (string.IsNullOrEmpty(wlc))
                    {
                        wlc = "Hi there {namelink}";
                    }

                    wlc = ParseWelcome(wlc, update.Message.Chat, n.Sender);

                    await botClient.SendTextMessageAsync(n.ChatId, wlc, ParseMode.Html);
                }
            }

            return(true);
        }
Example #2
0
        public async Task <bool> Process(ITelegramBotClient botClient, Update update, NeededItems n)
        {
            await botClient.SendTextMessageAsync(n.ChatId,
                                                 $"{"!".ToHyperLink("https://github.com/immmdreza/LetsCodeBot")} سلام {HtmlEncoder.Default.Encode(n.Sender.FirstName)}، من یک ربات تلگرام هستم که برای اهداف آموزشی ساخته شده."
                                                 + $"\nبنابراین اگر با پلتفرم {"GitHub".ToHyperLink("https://github.com/")} آشنا باشی، می تونی سورس و کدهای تشکیل دهنده منو اونجا ببینی."
                                                 + $"\n\n{"سورس کد من در گیت هاب".ToHyperLink("https://github.com/immmdreza/LetsCodeBot")}"
                                                 + $"\n\nاگر مایل به بحث درباره ربات های تلگرام، برنامه نویسی آنها و بطور کلی برنامه نویسی هستی؛ می توانی در گروه {"Let's C#de".ToHyperLink("https://t.me/joinchat/NlFgP0nOX1mdM6FeA8grcQ")} به ما بپیوندی."
                                                 , ParseMode.Html);

            return(true);
        }
Example #3
0
        public async Task <bool> Process(ITelegramBotClient botClient, Update update, NeededItems n)
        {
            ChatMember[] admins = await botClient.GetChatAdministratorsAsync(n.ChatId);

            if (admins.Any(x => x.User.Id == n.Sender.Id))
            {
                GroupServices c = new GroupServices();

                switch (n.Params[0])
                {
                case "/setwelcome":
                {
                    if (string.IsNullOrEmpty(update.Message.ReplyToMessage.Text))
                    {
                        return(true);
                    }

                    Models.BaseModels.Group chat = await c.GetByTlId(n.ChatId);

                    await c.UpdateWelcome(n.ChatId, update.Message.ReplyToMessage.Text);


                    try
                    {
                        await botClient.SendTextMessageAsync(n.ChatId, update.Message.ReplyToMessage.Text, ParseMode.Html);
                    }
                    catch (Exception ex)
                    {
                        await botClient.SendTextMessageAsync(n.ChatId, ex.Message, ParseMode.Html);
                    }
                    await botClient.SendTextMessageAsync(n.ChatId, "Done!");

                    return(true);
                }

                case "/setabout":
                {
                    if (string.IsNullOrEmpty(update.Message.ReplyToMessage.Text))
                    {
                        return(true);
                    }

                    Models.BaseModels.Group chat = await c.GetByTlId(n.ChatId);

                    await c.UpdateAbout(n.ChatId, update.Message.ReplyToMessage.Text);

                    try
                    {
                        await botClient.SendTextMessageAsync(n.ChatId, update.Message.ReplyToMessage.Text, ParseMode.Html);
                    }
                    catch (Exception ex)
                    {
                        await botClient.SendTextMessageAsync(n.ChatId, ex.Message, ParseMode.Html);
                    }
                    await botClient.SendTextMessageAsync(n.ChatId, "Done!");

                    return(true);
                }

                default:
                    break;
                }
            }
            else
            {
                await botClient.SendTextMessageAsync(n.ChatId, "Admin only");
            }

            return(true);
        }