public BaseController(TelegramBotClient bot, CoreBotUser user, int messageId, long chatId) { Bot = bot; User = user; MessageId = messageId; ChatId = chatId; }
//Validate user access role public static bool ValidateAccess(MethodInfo methodInfo, CoreBotUser user) { Object[] attributes = methodInfo.GetCustomAttributes(true); foreach (var attribute in attributes) { if (attribute.GetType() == typeof(Role)) { var access = ((Role)attribute).UserAccess; if (user.UserAccess != access) { //CoreBot.SendMessage(chatId, "No access", ParseMode.Markdown); return(false); } } } return(true); }
public static CoreBotUser AddOrUpdateUser(CoreBotUser user) { var usr = Users.Set().FirstOrDefault(u => u.Id == user.Id); //Store Users if (usr == null) { //If new User then add Users.Add(user); Console.WriteLine($"New User {user.Name} {user.UserName}"); //Bot.SendTextMessageAsync(Config.AdminId, $"New User {user.Name} {user.UserName}"); } else { //Update User usr.ActiveAt = DateTime.UtcNow; } //Save to file ApplicationData.Users.SaveToFileAsync(); return(usr); }