Example #1
0
 public string setusers(List <MPSUser> users)
 {
     CurrentContext.ValidateAdmin();
     foreach (MPSUser u in users)
     {
         MPSUser ustore = new MPSUser(u.ID);
         ustore.FromAnotherObject(u);
         if (ustore.IsModified())
         {
             ustore.Store();
         }
     }
     return("OK");
 }
Example #2
0
    private static async void BotOnUpdateReceived(object sender, UpdateEventArgs e)
    {
        var message = e.Update.Message;

        if (Settings.CurrentSettings.TELEGRAMCOMPANYCHANNEL == message.Chat.Id.ToString())
        {
            //ignore company chats
            return;
        }

        if (message == null || message.Type != MessageType.Text)
        {
            return;
        }
        string text = message.Text.ToUpper();

        if (text == "/START")
        {
            await _client.SendTextMessageAsync(message.Chat.Id, $"Hi, {message.Chat.FirstName}, type /subscribe:xxx");

            await _client.SendTextMessageAsync(message.Chat.Id, "where xxx is the your phone number in intentional format: +375...");

            return;
        }
        else if (text.StartsWith(_comSubs))
        {
            string num = Regex.Replace(text.Remove(0, "_comSubs".Length), "[^0-9]", "");
            await _client.SendTextMessageAsync(message.Chat.Id, $"Your number is: {num}");

            MPSUser u = MPSUser.FindUserbyPhone(num);
            if (u == null)
            {
                await _client.SendTextMessageAsync(message.Chat.Id, $"User no found, phone: {num}");

                return;
            }
            await _client.SendTextMessageAsync(message.Chat.Id, $"User {u.PERSON_NAME} was found! Subscribing...");

            u.CHATID = message.Chat.Id.ToString();
            u.Store();
            await _client.SendTextMessageAsync(message.Chat.Id, $"User {u.PERSON_NAME} has been subscribed!");

            return;
        }
        await _client.SendTextMessageAsync(message.Chat.Id, "Wrong command. Press /start to see more information");
    }
Example #3
0
    private static async void BotOnUpdateReceived(object sender, UpdateEventArgs e)
    {
        var message = e.Update.Message;

        if (message != null && Settings.CurrentSettings.TELEGRAMSUPPORTGROUP == message.Chat.Id.ToString())
        {
            //ignore company chats
            return;
        }

        if (message == null || message.Type != MessageType.Text)
        {
            return;
        }
        string text = message.Text.ToUpper();

        if (text == "/START")
        {
            await _client.SendTextMessageAsync(message.Chat.Id, $"Hi, {message.Chat.FirstName}, type /subscribe:xxx");

            await _client.SendTextMessageAsync(message.Chat.Id, "where xxx is the your phone number in intentional format: +375...");

            return;
        }
        else if (text.StartsWith(_comSubs))
        {
            string num = Regex.Replace(text.Remove(0, "_comSubs".Length), "[^0-9]", "");
            await _client.SendTextMessageAsync(message.Chat.Id, $"Your number is: {num}");

            MPSUser u = MPSUser.FindUserbyPhone(num);
            if (u == null)
            {
                await _client.SendTextMessageAsync(message.Chat.Id, $"User no found, phone: {num}");

                return;
            }
            await _client.SendTextMessageAsync(message.Chat.Id, $"User {u.PERSON_NAME} was found! Subscribing...");

            u.SUPCHATID = message.Chat.Id.ToString();
            u.Store();
            await _client.SendTextMessageAsync(message.Chat.Id, $"User {u.PERSON_NAME} has been subscribed!");

            return;
        }
        List <MPSUser> ls = MPSUser.EnumAllSupporters();

        foreach (var user in ls)
        {
            if (user.SUPCHATCLIENTID == message.Chat.Id.ToString())
            {
                await _client.SendTextMessageAsync(user.SUPCHATID, message.Text);

                return;
            }
            if (user.SUPCHATID == message.Chat.Id.ToString())
            {
                if (!string.IsNullOrEmpty(user.SUPCHATCLIENTID))
                {
                    await _client.SendTextMessageAsync(user.SUPCHATCLIENTID, message.Text);

                    return;
                }
                else
                {
                    await _client.SendTextMessageAsync(user.SUPCHATID, "type /select to select user to answer");

                    return;
                }
            }
        }
        foreach (var user in ls)
        {
            await _client.SendTextMessageAsync(message.Chat.Id, $"{message.From.FirstName} {message.From.LastName} Sent the message:");

            await _client.SendTextMessageAsync(user.SUPCHATID, message.Text);
        }
        await _client.SendTextMessageAsync(message.Chat.Id, "Hi! Response to your message is pending...");
    }