public async Task HtopAsync() { string helpstring; List <KeyValuePair <ulong, RegisteredUserClass> > alist; List <SocketUser> blist = new List <SocketUser>(); EmbedBuilder builder = new EmbedBuilder(); builder.WithTitle($"Hangman top."); builder.WithColor(Discord.Color.DarkOrange); helpstring = ""; alist = RegisteredList.ToList(); alist.Sort((y, x) => x.Value.HangManScore.CompareTo(y.Value.HangManScore)); for (var i = 0; i <= 9; i++) { helpstring = helpstring + $"{i + 1}. <@{alist[i].Key}>" + Constants.vbCrLf; } builder.AddField("Name", helpstring, true); helpstring = ""; for (var i = 0; i <= 9; i++) { helpstring = helpstring + alist[i].Value.HangManScore + Constants.vbCrLf; } builder.AddField("Points", helpstring, true); await(ReplyAsync("", embed: builder.Build())); }
public async Task HangmanAsync() { if (RegisteredList.ContainsKey(Context.Message.Author.Id) == false) { RegisteredList.Add(Context.Message.Author.Id, new RegisteredUserClass() { DotaID = 0, DiscordID = Context.Message.Author.Id, Name = Context.Message.Author.Username }); try { using (UserContext cont = new UserContext()) { cont.Users.Add(new RegisteredUserClass() { DotaID = 0, DiscordID = Context.Message.Author.Id, Name = Context.Message.Author.Username }); await cont.SaveChangesAsync(); } } catch (Exception ex) { } } HangManGame.NewGame(Context.Message); }
public async Task registerAsync([Remainder] string text) { bool result; uint Userid; if (text.Contains("roshpit.ca") == false) { Discord.Rest.RestUserMessage mes; mes = (Discord.Rest.RestUserMessage)(await Context.Channel.GetMessageAsync(Context.Message.Id)); await mes.AddReactionAsync(await Context.Client.GetGuild(279649221517246464).GetEmoteAsync(425332435773816842)); } Uri link = new Uri("http://roshpit.ca"); try { link = new Uri(text, UriKind.Absolute); result = true; } catch (Exception ex) { result = false; } Userid = 0; result = uint.TryParse(link.Segments.Last(), out Userid); if (result) { if (RegisteredList.ContainsKey(Context.Message.Author.Id) == false) { HtmlWeb web = new HtmlWeb(); HtmlDocument doc; doc = web.Load($"https://www.roshpit.ca/players/{Userid}"); HtmlNode a = doc.DocumentNode.SelectSingleNode($"//span[@id={Strings.Chr(34)}index-title{Strings.Chr(34)}]"); if (a == null) { return; } RegisteredList.Add(Context.Message.Author.Id, new RegisteredUserClass() { DotaID = Userid, DiscordID = Context.Message.Author.Id, Name = (System.Net.WebUtility.HtmlDecode((a.InnerText.Replace(Constants.vbLf, "").Replace(Constants.vbTab, "")))).Trim() }); renewRegisterList = true; try { using (UserContext cont = new UserContext()) { cont.Users.Add(new RegisteredUserClass() { DotaID = Userid, DiscordID = Context.Message.Author.Id, Name = (System.Net.WebUtility.HtmlDecode((a.InnerText.Replace(Constants.vbLf, "").Replace(Constants.vbTab, "")))).Trim() }); await cont.SaveChangesAsync(); } } catch (Exception ex) { } //try //{ // using (UserContext cont = new UserContext()) // { // cont.Users.UpdateRange(RegisteredList.Values.ToList()); // await cont.SaveChangesAsync(); // } //} //catch (Exception ex) //{ } Discord.Rest.RestUserMessage mes; mes = (Discord.Rest.RestUserMessage)(await Context.Message.Channel.GetMessageAsync(Context.Message.Id)); await mes.AddReactionAsync(await Context.Client.GetGuild(279649221517246464).GetEmoteAsync(425332394422173706)); return; } else { Discord.Rest.RestUserMessage mes; mes = (Discord.Rest.RestUserMessage)(await Context.Message.Channel.GetMessageAsync(Context.Message.Id)); await mes.AddReactionAsync(await Context.Client.GetGuild(279649221517246464).GetEmoteAsync(425332435773816842)); // Dim dmchan As SocketDMChannel = Await arg.Author.GetOrCreateDMChannelAsync() await ReplyAsync($"Sorry {Context.Message.Author.Mention}, you already registered as [{RegisteredList[Context.Message.Author.Id].Name}]({RegisteredList[Context.Message.Author.Id].DotaID}). If you made a mistake in ID, send PM to {(await Context.Message.Channel.GetUserAsync(216861458196201484)).Mention}"); return; } } else { Discord.Rest.RestUserMessage mes; mes = (Discord.Rest.RestUserMessage)(await Context.Message.Channel.GetMessageAsync(Context.Message.Id)); await mes.AddReactionAsync(await Context.Client.GetGuild(279649221517246464).GetEmoteAsync(425332435773816842)); // Dim dmchan As SocketDMChannel = Await arg.Author.GetOrCreateDMChannelAsync await ReplyAsync($"You are trying to register wrong roshpit.ca profile link. Check your information And try again."); return; } }