Example #1
0
 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);
 }
Example #2
0
        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;
            }
        }