public static async Task ListCharacters(IUser user, IMessageChannel chan, string prefix = null) { var chars = BotUser.GetCharFiles(user.Id); if (chars.Count < 1) { await chan.SendMessageAsync($"No characters found, use ``{prefix}New Character characternamehere`` to create characters"); } else { string list = ArrayM.ToString(chars, Environment.NewLine); EmbedBuilder em = DUtils.BuildEmbed(user.Username + "'s Characters", list, null, default, DUtils.NewField("Commands", "`Load charactername` & `Delete charactername`"));
public IActionResult GetDiscord(string token) { HttpWebRequest request = WebServer.Request("https://discord.com/api/users/@me"); request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token); string discordResponse = WebServer.ReadRequest(request); //Parse discord user data Dictionary <string, string> data = Utils.JSON <Dictionary <string, string> >(discordResponse); ulong userId = ulong.Parse(data["id"]); BotUser botUser = BotUser.Load(userId); return(Ok("{" + $"discord: {discordResponse}," + Environment.NewLine + $"server: {{ {Utils.JSON(botUser)} }}," + $"characters: {{ {Utils.JSON(BotUser.GetCharFiles(userId))} }}," + "}")); }
public async Task StartGame( [Summary("The name for your character. If empty, will take your discord username. " + "If your discord username is not valid, it will use a random name")] [Remainder] string character_name = null) { string charname = null; ulong playerID = Context.User.Id; if (character_name == null) { character_name = Regex.Replace(Context.User.Username, @"[^a-zA-Z'\-’\s]", ""); if (character_name == null || character_name.Length < 2) { character_name = "~rng"; } else if (character_name.Length > 28) { character_name = character_name.Substring(0, 28); } } if (character_name.ToLower() == "~rng") { charname = RandomName.ARandomName(); if (Program.rng.Next(3) == 0) { charname += " " + RandomName.ARandomName(); } if (Program.rng.Next(5) == 0) { charname += " " + RandomName.ARandomName(); } } else { charname = character_name; } if (Context.User.Id != 201875246091993088 && IllegalNames.Contains(charname.ToLower())) { throw NeitsilliaError.ReplyError($"The name {charname} is not allowed, you fool."); } List <Player> characters = BotUser.GetCharFiles(playerID); Match nameResult = Regex.Match(charname, @"^(\w|'|-|’|\s)+$"); int maxChar = ReferenceData.maxCharacterCount + Context.BotUser.membershipLevel; if (characters.Count >= maxChar) { DUtils.DeleteMessage(await ReplyAsync($"You may not have more than {maxChar} characters"), 1); } else if (!nameResult.Success) { DUtils.DeleteMessage(await ReplyAsync("Name must only contain A to Z, (-), ('), (’) and spaces"), 1); } else if (charname.Length < 2 || charname.Length > 28) { DUtils.DeleteMessage(await ReplyAsync("Name must be 2 to 28 characters"), 1); } else if (characters.Find((x) => x.name.ToLower().Equals(charname.ToLower())) != null) { DUtils.DeleteMessage(await ReplyAsync("Character name already used."), 1); } else { if (Context.BotUser.dateInscription.Year == 1) { Context.BotUser.dateInscription = DateTime.UtcNow; Context.BotUser.Save(); } Player player = new Player(Context.BotUser, charname); player.userSettings.RGB = GetRoleColor(Context.User, Context.Guild); player.SaveFileMongo(); await DUtils.DeleteContextMessageAsync(Context); await AutoCharacter(player, Context.Channel, true); } }