public static void ChangeGroupLang(Message msg, string[] args) { if (args == null) { return; } var lang = args[1]; try { using (var db = new SixNimmtDb()) { var p = db.Groups.FirstOrDefault(x => x.GroupId == msg.Chat.Id); if (p != null) { p.Language = lang; db.SaveChanges(); Bot.Send(msg.Chat.Id, "OK"); } } } catch { } }
public static void SetLang(Message msg, string[] args) { var id = msg.From.Id; //make sure the user is in the database using (var db = new SixNimmtDb()) { var user = db.Players.FirstOrDefault(x => x.TelegramId == id); if (user == null) { user = Helpers.MakeDefaultPlayer(msg.From); db.Players.Add(user); } user.UserName = msg.From.Username; user.Name = msg.From.FirstName; db.SaveChanges(); } var menu = Handler.GetConfigLangMenu(msg.From.Id, true); Bot.Send(msg.From.Id, GetTranslation("ChoosePMLanguage", GetLanguage(msg.From.Id)), replyMarkup: menu); }
public static void FullInfo(Message msg, string[] args) { Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; string buildDate = new DateTime(2000, 1, 1).Add(new TimeSpan( TimeSpan.TicksPerDay * version.Build + // days since 1 January 2000 TimeSpan.TicksPerSecond * 2 * version.Revision)).ToString(); string uptime = $"{(DateTime.Now - Program.Startup):dd\\.hh\\:mm\\:ss\\.ff}"; int gamecount = Bot.Games.Count; int playercount = Bot.Games.Select(x => x.Players.Count).Sum(); var toSend = ""; foreach (var g in Bot.Games.ToList().OrderBy(x => x.Phase)) { if (g.Phase == SixNimmt.GamePhase.InGame) { toSend += $"{g.GroupName.ToBold()}:\n--- {g.Players.Count.ToCode()} Players; Round {g.Round.ToCode()}\n"; } else { toSend += $"{g.GroupName.ToBold()}:\n--- {g.Players.Count.ToCode()} Players; {g.Phase.ToCode()}\n"; } } Bot.Send(msg.Chat.Id, $"Version: {version.ToString().ToCode()}\nBuild Date: {buildDate.ToCode()}\nUptime: {uptime.ToCode()}\nGame count: {gamecount.ToString().ToCode()}\nPlayer count: {playercount.ToString().ToCode()}\n\n{toSend}"); }
public static void AddAchv(Message msg, string[] args) { //get the user to add the achievement to //first, try by reply var id = 0; var achIndex = 0; var param = args[1].Split(' '); if (msg.ReplyToMessage != null) { var m = msg.ReplyToMessage; while (m.ReplyToMessage != null) { m = m.ReplyToMessage; } //check for forwarded message id = m.From.Id; if (m.ForwardFrom != null) { id = m.ForwardFrom.Id; } } else { //ok, check for a user mention var e = msg.Entities?.FirstOrDefault(); if (e != null) { switch (e.Type) { case MessageEntityType.Mention: //get user var username = msg.Text.Substring(e.Offset + 1, e.Length - 1); using (var db = new SixNimmtDb()) { id = db.Players.FirstOrDefault(x => x.UserName == username)?.TelegramId ?? 0; } break; case MessageEntityType.TextMention: id = e.User.Id; break; } achIndex = 1; } } if (id == 0) { //check for arguments then if (int.TryParse(param[0], out id)) { achIndex = 1; } else if (int.TryParse(param[1], out id)) { achIndex = 0; } } if (id != 0) { //try to get the achievement if (Enum.TryParse(param[achIndex], out Achievements a)) { //get the player from database using (var db = new SixNimmtDb()) { var p = db.Players.FirstOrDefault(x => x.TelegramId == id); if (p != null) { if (p.Achievements == null) { p.Achievements = 0; } var ach = (Achievements)p.Achievements; if (ach.HasFlag(a)) { msg.Reply("This player already have this achivement!"); return; //no point making another db call if they already have it } ach = ach | a; p.Achievements = (long)ach; db.SaveChanges(); var achvMsg = GetTranslation("NewUnlocks", GetLanguage(p.TelegramId)).ToBold() + Environment.NewLine + Environment.NewLine; achvMsg += $"{a.GetAchvName(GetLanguage(p.TelegramId)).ToBold()}\n{a.GetAchvDescription(GetLanguage(p.TelegramId))}"; Bot.Send(p.TelegramId, achvMsg); msg.Reply($"Achievement {a} unlocked for {p.Name}"); } } } } else { msg.Reply("Please reply to a (forwarded) message of the player, or provide the ID/Username/Mention."); } }
public static void Maintenance(Message msg, string[] args) { Program.MaintMode = !Program.MaintMode; Bot.Send(msg.Chat.Id, $"Maintenance Mode: {Program.MaintMode}"); }