Exemplo n.º 1
0
        public async Task MainAsync()
        {
            // You should dispose a service provider created using ASP.NET
            // when you are finished using it, at the end of your app's lifetime.
            // If you use another dependency injection framework, you should inspect
            // its documentation for the best way to do this.
            using (var services = ConfigureServices())
            {
                var client = services.GetRequiredService <DiscordSocketClient>();
                RoshpitStats.Load();

                string configuration;
                configuration = File.ReadAllText("config.json");
                conf          = JsonConvert.DeserializeObject <Config>(configuration);
                client.Log   += LogAsync;
                services.GetRequiredService <CommandService>().Log += LogAsync;

                // Tokens should be considered secret data and never hard-coded.
                // We can read from the environment variable to avoid hardcoding.
                await client.LoginAsync(TokenType.Bot, conf.token);

                await client.StartAsync();

                // Here we initialize the logic required to register our commands.
                await services.GetRequiredService <CommandHandlingService>().InitializeAsync();

                await Task.Delay(Timeout.Infinite);
            }
        }
Exemplo n.º 2
0
        public Task Seren7Async()
        {
            if (lastModifiedSeren.AddMinutes(5) < DateTime.Now)
            {
                lastModifiedSeren = RoshpitStats.GetSerenTop();
            }


            EmbedBuilder builder = new EmbedBuilder()
            {
                Title = "Serengaard this week Top 10"
            };

            builder.WithColor(Color.DarkGreen);
            builder.WithFooter($"Requested by {Context.User.Username}. Updated  { (DateTime.Now - lastModifiedSeren).TotalSeconds} seconds ago.");
            int counter = 0;

            foreach (Seven item in RoshpitStats.Seren_Top.seven)
            {
                string strNames;
                string strHeroes;
                strNames  = "";
                strHeroes = "";
                // If counter = 9 Then Exit For
                counter  += 1;
                strHeroes = $"{counter} place. Wave {item.wave_number}";
                if ((item.steam_name1) == null)
                {
                }
                else
                {
                    strNames = strNames + $"{RoshpitStats.Heroes[item.hero1]} [{item.steam_name1}](http://www.roshpit.ca/players/{item.steam_id1})" + "\r\n";
                }
                if ((item.steam_name2) == null)
                {
                }
                else
                {
                    strNames = strNames + $"{RoshpitStats.Heroes[item.hero2]} [{item.steam_name2}](http://www.roshpit.ca/players/{item.steam_id2})" + "\r\n";
                }
                if ((item.steam_name3) == null)
                {
                }
                else
                {
                    strNames = strNames + $"{RoshpitStats.Heroes[item.hero3]} [{item.steam_name3}](http://www.roshpit.ca/players/{item.steam_id3})" + "\r\n";
                }
                if ((item.steam_name4) == null)
                {
                }
                else
                {
                    strNames = strNames + $"{RoshpitStats.Heroes[item.hero4]} [{item.steam_name4}](http://www.roshpit.ca/players/{item.steam_id4})" + "\r\n";
                }
                if (strHeroes == "")
                {
                    strHeroes = "Unknown Heroes";
                }
                if (strNames == "")
                {
                    strNames = "Unknown Team";
                }
                builder.AddField(strHeroes, strNames, true);
            }
            // builder.WithDescription(strNames)
            return(ReplyAsync("", embed: builder.Build()));
        }
Exemplo n.º 3
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            if (message.MentionedRoles.Count > 0)
            {
                await returnPing(message);
            }

            // This value holds the offset where the prefix ends
            var argPos = 0;

            // Perform prefix check. You may want to replace this with
            // (!message.HasCharPrefix('!', ref argPos))
            // for a more traditional command format like !help.
            if (message.Content.Contains("roshpit.ca/market/auction/"))
            {
                AuctionNewClass new_auc;
                string          helpstring;
                ItemClass       helpitem = new ItemClass();
                helpstring = Regex.Matches(message.Content, @"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?")[0].Value;
                new_auc    = RoshpitStats.GetOngoingAuction2(helpstring);
                helpitem   = RoshpitStats.Search(new_auc.item_name_en, true);
                if (helpitem == null)
                {
                    UpdateTablesClass a = new UpdateTablesClass();
                    helpitem = a.LoadItem($"https://www.roshpit.ca/items/{new_auc.roshpititem_variant}");
                    using (AuctionContext acontext = new AuctionContext())
                    {
                        int mid = 0;
                        foreach (KeyValuePair <string, ItemClass> item in RoshpitStats.ItemList)
                        {
                            if (mid < item.Value.id)
                            {
                                mid = item.Value.id;
                            }
                        }
                        helpitem.id = mid + 1;
                        acontext.Items.Add(helpitem);
                        acontext.SaveChanges();
                    }
                    RoshpitStats.ItemList.Add(helpitem.Name.ToLower(), helpitem);
                }
                if (helpitem == null)
                {
                    return;
                }
                EmbedBuilder builder = new EmbedBuilder();
                builder.WithAuthor(new EmbedAuthorBuilder {
                    IconUrl = message.Author.GetAvatarUrl(), Name = message.Author.Username
                });
                builder.WithTitle("Auction for **" + helpitem.Name + "**");
                builder.WithThumbnailUrl(helpitem.Image);
                builder.WithUrl(helpstring);
                //Rarity Color
                if (helpitem.Rarity == "Immortal")
                {
                    builder.WithColor(228, 174, 51);
                }
                else if (helpitem.Rarity == "Arcana")
                {
                    builder.WithColor(173, 229, 92);
                }
                else
                {
                    System.Drawing.Color col;
                    col = System.Drawing.ColorTranslator.FromHtml(helpitem.Rarity);
                    builder.WithColor(col.R, col.G, col.B);
                    builder.AddField(helpitem.Special_Ability, "Lv. " + helpitem.Required_level, true);
                }
                if (new_auc.level_req.HasValue)
                {
                    helpstring = $"Lv. {new_auc.level_req}\t";
                }
                else
                {
                    helpstring = "";
                }
                //Base Armor
                if ((new_auc.base_armor.HasValue) && (new_auc.base_magic_armor.HasValue) && (new_auc.base_armor > 0) && (new_auc.base_magic_armor > 0))
                {
                    helpstring = helpstring + $"{emoArmor} {new_auc.base_armor}\t{emoMagicArmor} {new_auc.base_magic_armor}\r\n";
                }
                else if (new_auc.base_armor.HasValue && new_auc.base_armor > 0)
                {
                    helpstring = helpstring + $"{emoArmor} {new_auc.base_armor}\r\n";
                }
                else if (new_auc.base_magic_armor.HasValue && new_auc.base_magic_armor > 0)
                {
                    helpstring = helpstring + $"{emoMagicArmor} {new_auc.base_magic_armor}\r\n";
                }

                //Sockets
                if (new_auc.socket1 == "none" || new_auc.socket1 == null)
                {
                    ;
                }
                else if (new_auc.socket1 == "open")
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains(new_auc.socket1))}";
                }
                else
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains($"{new_auc.socket1}{new_auc.socket1value}"))}";
                }
                if (new_auc.socket2 == "none" || new_auc.socket2 == null)
                {
                    ;
                }
                else if (new_auc.socket2 == "open")
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains(new_auc.socket2))}";
                }
                else
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains($"{new_auc.socket2}{new_auc.socket2value}"))}";
                }
                //Properties
                //Property1
                if (new_auc.property1name != null)
                {
                    if (new_auc.property1name.Contains("immortal*weapon"))
                    {
                        string hero;
                        hero = new_auc.roshpititem_variant.Split("_")[2];
                        if (hero == "axe")
                        {
                            hero = "redgeneral";
                        }
                        helpstring = helpstring + $"★ {RoshpitEmotes.Find(c => c.ToString().Contains(hero))} **Weapon**\r\n";
                    }
                    else if (new_auc.property1name.Contains("arcana"))
                    {
                        string hero;
                        hero = new_auc.roshpititem_variant.Split("_")[2];
                        if (hero == "axe")
                        {
                            hero = "redgeneral";
                        }
                        helpstring = helpstring + $"★ {RoshpitEmotes.Find(c => c.ToString().Contains(hero))} **Arcana**\r\n";
                    }
                    else if (new_auc.property1name.Contains("immortal"))
                    {
                        helpstring = helpstring + $"★**{new_auc.property1name.Substring(21).Replace("_", " ")}**\r\n";
                    }
                    else
                    {
                        helpstring = helpstring + $"**{new_auc.property1name.Replace("_", " ")}** \t{new_auc.property1}\r\n";
                    }
                }
                //Property2 3 4
                if (new_auc.property2name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property2name.Replace("_", " ")}**\t{new_auc.property2}\r\n";
                }
                if (new_auc.property3name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property3name.Replace("_", " ")}**\t{new_auc.property3}\r\n";
                }
                if (new_auc.property4name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property4name.Replace("_", " ")}**\t{new_auc.property4}\r\n";
                }
                if (new_auc.property1name != null)
                {
                    builder.AddField("Properties:", helpstring, true);
                }

                //Bids
                helpstring = "";
                string emote = "";
                if (new_auc.resource_type == "Mithril Shards")
                {
                    emote = emoShard;
                }
                if (new_auc.resource_type == "Arcane Crystals")
                {
                    emote = emoCrystal;
                }
                if (new_auc.resource_type == "Prismatic Gemstones")
                {
                    emote = emoGem;
                }

                if (new_auc.minimum_bid > 0)
                {
                    helpstring = helpstring + $"\r\nStarting Bid:\t\t{emote}{new_auc.minimum_bid.ToString("#,##0")}";
                }
                if (new_auc.current_bid > 0)
                {
                    helpstring = helpstring + $"\r\nHighest Bid:\t\t{emote}{new_auc.current_bid.ToString("#,##0")}";
                }
                if (new_auc.buyout > 0)
                {
                    helpstring = helpstring + $"\r\nBuyout:\t\t{emote}{new_auc.buyout.ToString("#,##0")}";
                }
                helpstring = helpstring + "\r\n\\_\\_\\_\\_\\_\\_\\_\\_";
                //Time

                double hours;
                hours      = (new_auc.expiry_time - DateTime.Today).TotalHours - 12;
                helpstring = helpstring + $"\r\nExpiry:\t\t{hours.ToString("#,##0")} Hours\r\n";
                builder.AddField("Auction Details", helpstring, true);
                builder.Description = Regex.Replace(message.Content, @"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?", "");
                //
                await message.Channel.SendMessageAsync("", embed : builder.Build());

                Discord.Rest.RestUserMessage mes;
                mes = (Discord.Rest.RestUserMessage)(await message.Channel.GetMessageAsync(message.Id));
                await mes.DeleteAsync();
            }
            if ((!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) && (!message.HasCharPrefix(conf.prefix, ref argPos)))
            {
                return;
            }
            if ((message.Channel.Id == 391268932696145920) || (message.Channel.Id == 391268981446803466) || (message.Channel.Id == 331554376181219350) || (message.Channel.Id == 299731610683572224))
            {
                await message.Channel.SendMessageAsync("<:MonkaS:663460636490989597> 👉 <#431938235267284992>");

                return;
            }
            var context = new SocketCommandContext(_discord, message);
            // Perform the execution of the command. In this method,
            // the command service will perform precondition and parsing check
            // then execute the command if one is matched.
            await _commands.ExecuteAsync(context, argPos, _services);

            // Note that normally a result will be returned by this format, but here
            // we will handle the result in CommandExecutedAsync,
        }
Exemplo n.º 4
0
        public async Task rpcAsync([Remainder] string text)
        {
            ItemClass helpItem;
            String    helpstring = "";

            if (text.Length < 3)
            {
                return;
            }
            helpItem = RoshpitStats.Search(text);
            if (helpItem.Name == null)
            {
                await ReplyAsync($"Sorry, I don't know anything about this.{emoAkaShrug}");
            }
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithFooter($"Requested by {Context.User.Username}.");
            builder.WithTitle("**" + helpItem.Name + "**");
            builder.WithThumbnailUrl(helpItem.Image);
            if (helpItem.AlternativeName.Contains("https:") || helpItem.AlternativeName.Contains("http:"))
            {
                builder.WithUrl(helpItem.AlternativeName);
            }
            else
            {
                builder.WithUrl("http://www.roshpit.ca/items/item_rpc_" + helpItem.AlternativeName);
            }

            if (helpItem.Rarity == "Immortal")
            {
                builder.WithColor(228, 174, 51);
                builder.AddField(helpItem.Rarity, helpItem.Slot, true);
            }
            else if (helpItem.Rarity == "Arcana")
            {
                builder.WithColor(173, 229, 92);
                builder.AddField(helpItem.Rarity, helpItem.Slot, true);
            }
            else
            {
                System.Drawing.Color col;
                col = System.Drawing.ColorTranslator.FromHtml(helpItem.Rarity);
                builder.WithColor(col.R, col.G, col.B);
                builder.AddField("Lv. " + helpItem.Required_level, helpItem.Slot, true);
            }
            if (helpItem.Rolls.Count > 0)
            {
                foreach (string roll in helpItem.Rolls)
                {
                    if (roll.Contains("Property"))
                    {
                        Match  mat = Regex.Match(roll, "\\w+Property\\d");
                        string roll2;
                        roll2      = Regex.Replace(roll, mat.Value, $"[{mat.Value}](http://roshpit.wikia.com/wiki/{mat.Value})");
                        helpstring = helpstring + "■    " + roll2 + "\r\n";
                    }
                    else
                    {
                        helpstring = helpstring + "■    " + roll + "\r\n";
                    }
                }
                builder.AddField("Rolls", helpstring, true);
            }
            if (helpItem.Special_Ability_Description != "")
            {
                if (helpItem.Special_Ability_Element == "")
                {
                    builder.AddField("★" + helpItem.Special_Ability, helpItem.Special_Ability_Description, false);
                }
                else
                {
                    builder.AddField("★" + helpItem.Special_Ability, $"__Damage type__         **{helpItem.Special_Ability_Damage_Type}**\r\n\t"
                                     + $"__Element__               **{helpItem.Special_Ability_Element}**\r\n\r\n" + helpItem.Special_Ability_Description, true);
                }
            }
            await ReplyAsync("", embed : builder.Build());
        }