Пример #1
0
        public async Task GetUserSeason(EventContext e)
        {
            int platform = 1;

            string[] arg      = e.arguments.Split(' ');
            int      seasonId = int.Parse(arg[1]);

            if (arg.Length > 2)
            {
                platform = GetPlatform(arg[2]);
            }

            IDiscordEmbed    embed = Utils.Embed;
            RocketLeagueUser user  = await TryGetUser(arg[0], platform);

            if (user == null)
            {
                embed.Title        = "Uh oh!";
                embed.Description  = $"We couldn't find a user with the name `{arg[0]}`. Please look up yourself on https://rlstats.com/ to create your profile!";
                embed.ThumbnailUrl = "http://miki.veld.one/assets/img/rlstats-logo.png";
                await embed.QueueToChannel(e.Channel);

                return;
            }

            embed.Title = $"{user.DisplayName}'s Season {arg[1]}";

            if (user.RankedSeasons.ContainsKey(seasonId))
            {
                Dictionary <int, RocketLeagueRankedStats> rankedseason = user.RankedSeasons[seasonId];

                foreach (RocketLeaguePlaylist playlist in api.playlists.Data)
                {
                    if (rankedseason.ContainsKey(playlist.Id))
                    {
                        if (playlist.PlatformId == platform)
                        {
                            RocketLeagueRankedStats stats = rankedseason[playlist.Id];

                            string           rank = "";
                            RocketLeagueTier t    = api.tiers.Data.Find(z => { return(z.Id == stats.Tier); });

                            if (t != null)
                            {
                                rank = t.Name + " " + stats.Division;

                                embed.AddInlineField(playlist.Name.Substring(7), $"Rank: {rank}\n\nMMR: {stats.RankPoints}\nMatches Played: {stats.MatchesPlayed}");
                            }
                        }
                    }
                }
            }

            await embed.QueueToChannel(e.Channel);
        }
Пример #2
0
        public async Task GetUser(EventContext e)
        {
            string[] arg      = e.arguments.Split(' ');
            int      platform = 1;

            if (arg.Length > 1)
            {
                platform = GetPlatform(arg[1]);
            }

            IDiscordEmbed embed = Utils.Embed;

            RocketLeagueUser user = await TryGetUser(arg[0], platform);

            if (user == null)
            {
                embed.Title        = "Uh oh!";
                embed.Description  = $"We couldn't find a user with the name `{arg[0]}`. Please look up yourself on https://rlstats.com/ to create your profile!";
                embed.ThumbnailUrl = "http://miki.veld.one/assets/img/rlstats-logo.png";
                await embed.QueueToChannel(e.Channel);

                return;
            }

            embed.Title = user.DisplayName;

            foreach (RocketLeagueSeason season in api.seasons.Data)
            {
                if (user.RankedSeasons.ContainsKey(season.Id))
                {
                    Dictionary <int, RocketLeagueRankedStats> rankedseason = user.RankedSeasons[season.Id];
                    string s = "";

                    foreach (RocketLeaguePlaylist playlist in api.playlists.Data)
                    {
                        if (rankedseason.ContainsKey(playlist.Id))
                        {
                            if (playlist.PlatformId == platform)
                            {
                                RocketLeagueRankedStats stats = rankedseason[playlist.Id];
                                s += "`" + playlist.Name.Substring(7).PadRight(13) + ":` " + stats.RankPoints.ToString() + " MMR\n";
                            }
                        }
                    }

                    embed.AddInlineField("Season" + season.Id, s);
                }
            }

            embed.ThumbnailUrl = user.AvatarUrl;
            embed.ImageUrl     = user.SignatureUrl;
            await embed.QueueToChannel(e.Channel);
        }
Пример #3
0
        public async Task PunchAsync(EventContext e)
        {
            string[] images = new string[]
            {
                "http://imgur.com/jVc3GGv.gif",
                "http://imgur.com/iekwz4h.gif",
                "http://imgur.com/AbRmlAo.gif",
                "http://imgur.com/o5MoMYi.gif",
                "http://imgur.com/yNfMX9B.gif",
                "http://imgur.com/bwXvfKE.gif",
                "http://imgur.com/6wKJVHy.gif",
                "http://imgur.com/kokCK1I.gif",
                "http://imgur.com/E3CtvPV.gif",
                "http://imgur.com/q7AmR8n.gif",
                "http://imgur.com/pDohPrm.gif",
            };

            Random r = new Random();

            IDiscordEmbed embed = Utils.Embed;

            if (e.arguments.Length > 0)
            {
                embed.Title = $"{e.Author.Username} punches {e.message.RemoveMentions(e.arguments)}";
            }
            else
            {
                embed.Title = $"{e.message.Bot.Username} punches {e.Author.Username}";
            }
            embed.ImageUrl = images[r.Next(0, images.Length)];

            await embed.QueueToChannel(e.Channel);
        }
Пример #4
0
        public async Task GuildTop(EventContext e)
        {
            int amountToTake = 12;

            int.TryParse(e.arguments, out int amountToSkip);

            using (var context = new MikiContext())
            {
                int totalGuilds = (int)Math.Ceiling((double)await context.GuildUsers.CountAsync() / amountToTake);

                List <GuildUser> leaderboards = await context.GuildUsers.OrderByDescending(x => x.Experience)
                                                .Skip(amountToSkip * amountToTake)
                                                .Take(amountToTake)
                                                .ToListAsync();

                IDiscordEmbed embed = Utils.Embed
                                      .SetTitle(e.GetResource("guildtop_title"));

                foreach (GuildUser i in leaderboards)
                {
                    embed.AddInlineField(i.Name, i.Experience.ToString());
                }

                embed.SetFooter(e.GetResource("page_index", amountToSkip + 1, totalGuilds), null);
                await embed.QueueToChannel(e.Channel);
            }
        }
Пример #5
0
        public async Task ToggleGuildNotifications(EventContext e)
        {
            using (var context = new MikiContext())
            {
                Setting setting = await context.Settings.FindAsync(e.Guild.Id.ToDbLong(), DatabaseSettingId.CHANNELMESSAGE);

                if (setting == null)
                {
                    setting = context.Settings.Add(new Setting()
                    {
                        EntityId  = e.Guild.Id.ToDbLong(),
                        IsEnabled = true,
                        SettingId = DatabaseSettingId.CHANNELMESSAGE
                    }).Entity;
                }

                IDiscordEmbed embed  = Utils.Embed;
                Locale        locale = Locale.GetEntity(e.Channel.Id.ToDbLong());
                setting.IsEnabled = !setting.IsEnabled;

                string aa = (!setting.IsEnabled) ? locale.GetString("miki_generic_disabled") : locale.GetString("miki_generic_enabled");

                embed.Description = locale.GetString("miki_module_settings_guild_notifications", aa);
                embed.Color       = (setting.IsEnabled) ? new IA.SDK.Color(1, 0, 0) : new IA.SDK.Color(0, 1, 0);

                await context.SaveChangesAsync();

                await embed.QueueToChannel(e.Channel);
            }
        }
Пример #6
0
        public async Task SpellCheckAsync(EventContext context)
        {
            IDiscordEmbed embed = Utils.Embed;

            embed.SetTitle("Spellcheck - top results");

            API.StringComparison.StringComparer          sc   = new API.StringComparison.StringComparer(context.commandHandler.GetAllEventNames());
            List <API.StringComparison.StringComparison> best = sc.CompareToAll(context.arguments)
                                                                .OrderBy(z => z.score)
                                                                .ToList();
            int x = 1;

            foreach (API.StringComparison.StringComparison c in best)
            {
                embed.AddInlineField($"#{x}", c);
                x++;
                if (x > 16)
                {
                    break;
                }
            }

            embed.QueueToChannel(context.Channel);

            await Task.Yield();
        }
Пример #7
0
        public async Task SlapAsync(EventContext e)
        {
            string[] images = new string[]
            {
                "http://i.imgur.com/GQtzDsV.gif",
                "http://i.imgur.com/rk8eqnt.gif",
                "http://i.imgur.com/UnzGS24.gif",
                "http://i.imgur.com/CHbRGnV.gif",
                "http://i.imgur.com/DvwnC0r.gif",
                "http://i.imgur.com/Ksy8dvd.gif",
                "http://i.imgur.com/b75B4qM.gif",
                "http://i.imgur.com/d9thUdx.gif",
                "http://i.imgur.com/iekwz4h.gif",
                "http://i.imgur.com/q7AmR8n.gif",
                "http://i.imgur.com/pDohPrm.gif",
            };

            Random r = new Random();

            IDiscordEmbed embed = Utils.Embed;

            if (e.arguments.Length > 0)
            {
                embed.Title = $"{e.Author.Username} slaps {e.message.RemoveMentions(e.arguments)}";
            }
            else
            {
                embed.Title = $"{e.message.Bot.Username} slaps {e.Author.Username}";
            }
            embed.ImageUrl = images[r.Next(0, images.Length)];

            await embed.QueueToChannel(e.Channel);
        }
Пример #8
0
        public async Task UrbanAsync(EventContext e)
        {
            if (string.IsNullOrEmpty(e.arguments))
            {
                return;
            }

            Locale               locale = new Locale(e.Channel.Id);
            UrbanDictionaryApi   api    = new UrbanDictionaryApi(Global.Config.UrbanKey);
            UrbanDictionaryEntry entry  = await api.GetEntryAsync(e.arguments);

            if (entry != null)
            {
                IDiscordEmbed embed = Utils.Embed
                                      .SetAuthor(entry.Term,
                                                 "http://cdn9.staztic.com/app/a/291/291148/urban-dictionary-647813-l-140x140.png",
                                                 "http://www.urbandictionary.com/define.php?term=" + e.arguments)
                                      .SetDescription(locale.GetString("miki_module_general_urban_author", entry.Author));

                embed.AddInlineField(locale.GetString("miki_module_general_urban_definition"), entry.Definition);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_example"), entry.Example);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_rating"), "👍 " + entry.ThumbsUp + "  👎 " + entry.ThumbsDown);

                embed.QueueToChannel(e.Channel);
            }
            else
            {
                e.ErrorEmbed(e.GetResource("error_term_invalid"))
                .QueueToChannel(e.Channel.Id);
            }
        }
Пример #9
0
        public async Task PokeAsync(EventContext e)
        {
            string[] images = new string[]
            {
                "http://i.imgur.com/WG8EKwM.gif",
                "http://i.imgur.com/dfoxby7.gif",
                "http://i.imgur.com/TzD1Ngz.gif",
                "http://i.imgur.com/i1hwvQu.gif",
                "http://i.imgur.com/bStOFsM.gif",
                "http://i.imgur.com/1PBeB9H.gif",
                "http://i.imgur.com/3kerpju.gif",
                "http://i.imgur.com/uMBRFjX.gif",
                "http://i.imgur.com/YDJFoBV.gif",
                "http://i.imgur.com/urC9B1H.gif"
            };

            Random r = new Random();

            IDiscordEmbed embed = Utils.Embed;

            if (e.arguments.Length > 0)
            {
                embed.Title = $"{e.Author.Username} pokes {e.message.RemoveMentions(e.arguments)}";
            }
            else
            {
                embed.Title = $"{e.message.Bot.Username} pokes {e.Author.Username}";
            }
            embed.ImageUrl = images[r.Next(0, images.Length)];

            await embed.QueueToChannel(e.Channel);
        }
Пример #10
0
        public async Task CuddleAsync(EventContext e)
        {
            string[] images = new string[]
            {
                "http://i.imgur.com/CEkg7K3.gif",
                "http://i.imgur.com/K4lYduH.gif",
                "http://i.imgur.com/8kLQ55E.gif",
                "http://i.imgur.com/kd0F5bV.gif",
                "http://i.imgur.com/zG60zPk.gif",
                "http://i.imgur.com/ct76LIg.gif",
                "http://i.imgur.com/guBWT22.gif",
                "http://i.imgur.com/Asnv32U.gif"
            };

            Random r = new Random();

            IDiscordEmbed embed = Utils.Embed;

            if (e.arguments.Length > 0)
            {
                embed.Title = $"{e.Author.Username} cuddles with {e.message.RemoveMentions(e.arguments)}";
            }
            else
            {
                embed.Title = $"{e.message.Bot.Username} cuddles with {e.Author.Username}";
            }
            embed.ImageUrl = images[r.Next(0, images.Length)];

            await embed.QueueToChannel(e.Channel);
        }
Пример #11
0
        public static void SendAchievement(BaseAchievement d, IDiscordMessageChannel channel, IDiscordUser user)
        {
            IDiscordEmbed embed = Utils.Embed.SetTitle("Achievement Unlocked")
                                  .SetDescription($"{d.Icon} **{user.Username}#{user.Discriminator}** has unlocked the achievement **{d.Name}**! {d.Icon}");

            embed.QueueToChannel(channel);
        }
Пример #12
0
        public async Task InfoAsync(EventContext e)
        {
            IDiscordEmbed embed  = Utils.Embed;
            Locale        locale = new Locale(e.Channel.Id);

            embed.Author      = embed.CreateAuthor();
            embed.Author.Name = "Miki " + Bot.Instance.Information.Version;
            embed.SetColor(0.6f, 0.6f, 1.0f);

            embed.AddField(locale.GetString("miki_module_general_info_made_by_header"),
                           locale.GetString("miki_module_general_info_made_by_description") + " Drummss, Fuzen, IA, Luke, Milk, n0t, Phanrazak, Rappy, Tal, Vallode, GrammarJew");


            embed.AddField(e.GetResource("miki_module_general_info_links"),
                           $"`{locale.GetString("miki_module_general_info_docs").PadRight(15)}:` [documentation](https://www.github.com/velddev/miki/wiki)\n" +
                           $"`{"donate".PadRight(15)}:` [patreon](https://www.patreon.com/mikibot) | [ko-fi](https://ko-fi.com/velddy)\n" +
                           $"`{locale.GetString("miki_module_general_info_twitter").PadRight(15)}:` [veld](https://www.twitter.com/velddev) | [miki](https://www.twitter.com/miki_discord)\n" +
                           $"`{locale.GetString("miki_module_general_info_reddit").PadRight(15)}:` [/r/mikibot](https://www.reddit.com/r/mikibot) \n" +
                           $"`{locale.GetString("miki_module_general_info_server").PadRight(15)}:` [discord](https://discord.gg/55sAjsW)\n" +
                           $"`{locale.GetString("miki_module_general_info_website").PadRight(15)}:` [link](https://miki.ai)");

            embed.QueueToChannel(e.Channel);

            await Task.Yield();
        }
Пример #13
0
        public async Task ConfigAsync(EventContext e)
        {
            IModule module = e.commandHandler.GetModule(e.arguments);

            if (module != null)
            {
                IDiscordEmbed embed = Utils.Embed.SetTitle(e.arguments.ToUpper());

                string content = "";

                foreach (RuntimeCommandEvent ev in module.Events.OrderBy((x) => x.Name))
                {
                    content += (await ev.IsEnabled(e.Channel.Id) ? "<:iconenabled:341251534522286080>" : "<:icondisabled:341251533754728458>") + " " + ev.Name + "\n";
                }

                embed.AddInlineField("Events", content);

                content = "";

                foreach (IService ev in module.Services.OrderBy((x) => x.Name))
                {
                    content += (await ev.IsEnabled(e.Channel.Id) ? "<:iconenabled:341251534522286080>" : "<:icondisabled:341251533754728458>") + " " + ev.Name + "\n";
                }

                if (!string.IsNullOrEmpty(content))
                {
                    embed.AddInlineField("Services", content);
                }

                embed.QueueToChannel(e.Channel);
            }
        }
Пример #14
0
        public async Task SteamRequestHandler(EventContext context)
        {
            IDiscordEmbed embed = Utils.Embed;

            embed.SetAuthor(steamAuthorName, steamAuthorIcon, "");
            embed.Description = "Steam API at your fingertips.\nYou can find a list of commands by typing `" + ">" + "help steam`!";
            embed.QueueToChannel(context.Channel);
        }
Пример #15
0
        public async Task SearchPasta(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong());

            if (string.IsNullOrWhiteSpace(e.arguments))
            {
                await Utils.ErrorEmbed(locale, e.GetResource("searchpasta_error_no_arg"))
                .QueueToChannel(e.Channel.Id);

                return;
            }

            List <string> arguments = e.arguments.Split(' ').ToList();
            int           page      = 0;

            if (arguments.Count > 1)
            {
                if (int.TryParse(arguments[arguments.Count - 1], out page))
                {
                    page -= 1;
                }
            }

            string query = arguments[0];

            using (var context = new MikiContext())
            {
                var pastasFound = await context.Pastas.Where(x => x.Id.ToLower().Contains(query.ToLower()))
                                  .OrderByDescending(x => x.Id)
                                  .Skip(25 * page)
                                  .Take(25)
                                  .ToListAsync();


                var totalCount = await context.Pastas.Where(x => x.Id.Contains(query))
                                 .CountAsync();

                if (pastasFound?.Count > 0)
                {
                    string resultString = "";

                    pastasFound.ForEach(x => { resultString += "`" + x.Id + "` "; });

                    IDiscordEmbed embed = Utils.Embed;
                    embed.Title       = e.GetResource("miki_module_pasta_search_header");
                    embed.Description = resultString;
                    embed.CreateFooter();
                    embed.Footer.Text = e.GetResource("page_index", page + 1, (Math.Ceiling((double)totalCount / 25)).ToString());

                    await embed.QueueToChannel(e.Channel);

                    return;
                }

                await Utils.ErrorEmbed(locale, e.GetResource("miki_module_pasta_search_error_no_results", arguments[0]))
                .QueueToChannel(e.Channel);
            }
        }
Пример #16
0
        public async Task FavouritePastaList(EventContext e, bool lovedPastas = true)
        {
            Locale       locale       = Locale.GetEntity(e.Channel.Id.ToDbLong());
            IDiscordUser targetUser   = e.Author;
            float        totalPerPage = 25f;
            int          page         = 0;

            if (e.message.MentionedUserIds.Count() >= 1)
            {
                targetUser = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First());

                string[] args = e.arguments.Split(' ');
                int.TryParse((args.Count() > 1 ? args[1] : "0"), out page);
                page -= page <= 0 ? 0 : 1;
            }
            else
            {
                int.TryParse(e.arguments, out page);
                page -= 1;
            }

            using (MikiContext context = new MikiContext())
            {
                long authorId = targetUser.Id.ToDbLong();
                IEnumerable <PastaVote> pastaVotes = context.Votes.Where(x => x.UserId == authorId && x.PositiveVote == lovedPastas);

                int maxPage = (int)Math.Floor(pastaVotes.Count() / totalPerPage);
                page = page > maxPage ? maxPage : page;
                page = page < 0 ? 0 : page;


                if (pastaVotes.Count() <= 0)
                {
                    string loveString  = (lovedPastas ? locale.GetString("miki_module_pasta_loved") : locale.GetString("miki_module_pasta_hated"));
                    string errorString = locale.GetString("miki_module_pasta_favlist_self_none", loveString);
                    if (e.message.MentionedUserIds.Count() >= 1)
                    {
                        errorString = locale.GetString("miki_module_pasta_favlist_mention_none", loveString);
                    }
                    await Utils.ErrorEmbed(e, errorString).QueueToChannel(e.Channel.Id);

                    return;
                }

                IDiscordEmbed    embed        = Utils.Embed;
                List <PastaVote> neededPastas = pastaVotes.Skip((int)totalPerPage * page).Take((int)totalPerPage).ToList();

                string resultString = "";
                neededPastas.ForEach(x => { resultString += "`" + x.Id + "` "; });

                string useName = string.IsNullOrEmpty(targetUser.Nickname) ? targetUser.Username : targetUser.Nickname;
                embed.SetTitle($"{( lovedPastas ? locale.GetString( "miki_module_pasta_loved_header" ) : locale.GetString( "miki_module_pasta_hated_header" ) )} - {useName}");
                embed.SetDescription(resultString);
                embed.SetFooter(locale.GetString("page_index", page + 1, Math.Ceiling(pastaVotes.Count() / totalPerPage)), "");

                await embed.QueueToChannel(e.Channel);
            }
        }
Пример #17
0
        [Command(Name = "steamhelp")]           // TODO: Kill this command. >help steam should be used instead.
        public async Task SteamHelpAsync(EventContext context)
        {
            IDiscordEmbed embed = Utils.Embed;

            embed.SetAuthor(steamAuthorName, steamAuthorIcon, "");
            embed.Description = "Steam API at your fingertips.";
            embed.AddInlineField("Commands", "`>steam` \n`>steam user <vanity/steam64>`");
            embed.QueueToChannel(context.Channel);
        }
Пример #18
0
        public void GetNowPlaying(EventContext e)
        {
            int platform = -1;

            if (!string.IsNullOrWhiteSpace(e.arguments))
            {
                platform = GetPlatform(e.arguments);
            }

            Dictionary <int, RocketLeaguePlaylist> d = new Dictionary <int, RocketLeaguePlaylist>();

            if (platform == -1)
            {
                foreach (RocketLeaguePlaylist p in api.playlists.Data)
                {
                    if (d.ContainsKey(p.Id))
                    {
                        d[p.Id].Population.Players += p.Population.Players;
                    }
                    else
                    {
                        RocketLeaguePlaylist playlist = new RocketLeaguePlaylist()
                        {
                            Id         = p.Id,
                            Name       = p.Name,
                            PlatformId = p.PlatformId,
                            Population = new RocketLeaguePopulation()
                            {
                                Players = p.Population.Players
                            }
                        };

                        d.Add(p.Id, playlist);
                    }
                }
            }
            else
            {
                foreach (RocketLeaguePlaylist p in api.playlists.Data)
                {
                    if (p.PlatformId == platform)
                    {
                        d.Add(p.Id, p);
                    }
                }
            }

            IDiscordEmbed embed = Utils.Embed;

            embed.Title = "Now Playing!";
            foreach (RocketLeaguePlaylist p in d.Values)
            {
                embed.AddField(api.playlists.Data.Find(z => { return(z.Id == p.Id); }).Name, p.Population.Players.ToString());
            }

            embed.QueueToChannel(e.Channel);
        }
Пример #19
0
 public static async Task SendChannel(IDiscordMessageChannel channel, IDiscordEmbed message)
 {
     if ((await channel.Guild.GetCurrentUserAsync()).HasPermissions(channel, DiscordGuildPermission.SendMessages))
     {
         if (CanSendNotification(channel.Guild.Id, DatabaseSettingId.CHANNELMESSAGE))
         {
             await message.QueueToChannel(channel);
         }
     }
 }
Пример #20
0
        public async Task GuildInfoAsync(EventContext e)
        {
            IDiscordEmbed embed = Utils.Embed;
            Locale        l     = Locale.GetEntity(e.Channel.Id.ToDbLong());

            embed.SetAuthor(e.Guild.Name, e.Guild.AvatarUrl, e.Guild.AvatarUrl);

            IDiscordUser owner = await e.Guild.GetOwnerAsync();

            embed.AddInlineField(
                "👑" + l.GetString("miki_module_general_guildinfo_owned_by"),
                owner.Username + "#" + owner.Discriminator);

            embed.AddInlineField(
                "👉" + l.GetString("miki_label_prefix"),
                await PrefixInstance.Default.GetForGuildAsync(e.Guild.Id));

            embed.AddInlineField(
                "📺" + l.GetString("miki_module_general_guildinfo_channels"),
                (await e.Guild.GetChannelCountAsync()).ToString());

            embed.AddInlineField(
                "🔊" + l.GetString("miki_module_general_guildinfo_voicechannels"),
                (await e.Guild.GetVoiceChannelCountAsync()).ToString());

            embed.AddInlineField(
                "🙎" + l.GetString("miki_module_general_guildinfo_users"),
                (await e.Guild.GetUserCountAsync()).ToString());

            embed.AddInlineField(
                "🤖" + l.GetString("term_shard"),
                Bot.instance.Client.GetShardIdFor((e.Guild as IProxy <IGuild>).ToNativeObject()));

            List <string> roleNames = new List <string>();

            foreach (IDiscordRole r in e.Guild.Roles)
            {
                roleNames.Add($"`{r.Name}`");
            }

            embed.AddInlineField(
                "#⃣" + l.GetString("miki_module_general_guildinfo_roles_count"),
                e.Guild.Roles.Count.ToString());

            string roles = string.Join(", ", roleNames);

            if (roles.Length <= 1000)
            {
                embed.AddInlineField(
                    "📜" + l.GetString("miki_module_general_guildinfo_roles"),
                    roles);
            }

            await embed.QueueToChannel(e.Channel);
        }
Пример #21
0
        public async Task AchievementsAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                Args      args     = new Args(e.arguments);
                ArgObject argument = args.First();

                long id = (long)e.Author.Id;

                if (argument != null)
                {
                    IDiscordUser user = await args.Join().GetUserAsync(e.Guild);

                    if (user != null)
                    {
                        id = (long)user.Id;
                    }
                }

                IDiscordUser discordUser = await e.Guild.GetUserAsync(id.FromDbLong());

                User u = await User.GetAsync(context, discordUser);

                List <Achievement> achievements = await context.Achievements
                                                  .Where(x => x.Id == id)
                                                  .ToListAsync();

                IDiscordEmbed embed = Utils.Embed
                                      .SetColor(255, 255, 255)
                                      .SetAuthor($"{u.Name} | " + "Achievements", discordUser.AvatarUrl, "https://miki.ai/profiles/ID/achievements");

                StringBuilder leftBuilder = new StringBuilder();

                int totalScore = 0;

                foreach (var a in achievements)
                {
                    BaseAchievement metadata = AchievementManager.Instance.GetContainerById(a.Name).Achievements[a.Rank];
                    leftBuilder.AppendLine(metadata.Icon + " | `" + metadata.Name.PadRight(15) + $"{metadata.Points.ToString().PadLeft(3)} pts` | 📅 {a.UnlockedAt.ToShortDateString()}");
                    totalScore += metadata.Points;
                }

                if (string.IsNullOrEmpty(leftBuilder.ToString()))
                {
                    embed.AddInlineField("Total Pts: " + totalScore, "None, yet.");
                }
                else
                {
                    embed.AddInlineField("Total Pts: " + totalScore, leftBuilder.ToString());
                }

                embed.QueueToChannel(e.Channel);
            }
        }
Пример #22
0
        public AccountManager(IBot bot)
        {
            OnGlobalLevelUp += async(a, e, l) =>
            {
                await Task.Yield();

                DogStatsd.Counter("levels.global", l);
            };
            OnLocalLevelUp += async(a, e, l) =>
            {
                DogStatsd.Counter("levels.local", l);

                long             guildId       = (long)e.Guild.Id;
                Locale           locale        = new Locale(e.Id);
                List <LevelRole> rolesObtained = new List <LevelRole>();

                using (var context = new MikiContext())
                {
                    rolesObtained = await context.LevelRoles
                                    .Where(p => p.GuildId == guildId && p.RequiredLevel == l && p.Automatic)
                                    .ToListAsync();
                }

                await a.AddRolesAsync(rolesObtained.Select(x => x.Role).ToArray());

                var setting = await Setting.GetAsync <LevelNotificationsSetting>(e.Id, DatabaseSettingId.LEVEL_NOTIFICATIONS);

                if (setting == LevelNotificationsSetting.NONE)
                {
                    return;
                }

                if (setting == LevelNotificationsSetting.REWARDS_ONLY && rolesObtained.Count == 0)
                {
                    return;
                }

                IDiscordEmbed embed = Utils.Embed
                                      .SetTitle(locale.GetString("miki_accounts_level_up_header"))
                                      .SetDescription(locale.GetString("miki_accounts_level_up_content", $"{a.Username}#{a.Discriminator}", l))
                                      .SetColor(1, 0.7f, 0.2f);

                if (rolesObtained.Count > 0)
                {
                    embed.AddInlineField("Rewards", string.Join("\n", rolesObtained.Select(x => $"New Role: **{x.Role.Name}**")));
                }

                embed.QueueToChannel(e);
            };

            bot.GuildUpdate += Client_GuildUpdated;
            bot.GuildJoin   += Client_UserJoined;
            bot.GuildLeave  += Client_UserLeft;
        }
Пример #23
0
        public async Task DumpShards(EventContext context)
        {
            IDiscordEmbed embed = Utils.Embed;

            embed.Title = "Shards";

            foreach (DiscordSocketClient c in Bot.instance.Client.Shards)
            {
                embed.AddInlineField("Shard " + c.ShardId, $"State:  {c.ConnectionState}\nPing:   {c.Latency}\nGuilds: {c.Guilds.Count}");
            }

            await embed.QueueToChannel(context.Channel);
        }
Пример #24
0
        public async Task SyncAvatarAsync(EventContext e)
        {
            string localFilename = @"c:\inetpub\miki.veld.one\assets\img\user\" + e.Author.Id + ".png";

            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(e.Author.GetAvatarUrl());
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // Check that the remote file was found. The ContentType
            // check is performed since a request for a non-existent
            // image file might be redirected to a 404-page, which would
            // yield the StatusCode "OK", even though the image was not
            // found.
            if ((response.StatusCode == HttpStatusCode.OK ||
                 response.StatusCode == HttpStatusCode.Moved ||
                 response.StatusCode == HttpStatusCode.Redirect) &&
                response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
            {
                // if the remote file was found, download oit
                using (Stream inputStream = response.GetResponseStream())
                    using (Stream outputStream = File.OpenWrite(localFilename))
                    {
                        byte[] buffer = new byte[4096];
                        int    bytesRead;
                        do
                        {
                            bytesRead = inputStream.Read(buffer, 0, buffer.Length);
                            outputStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead != 0);
                    }
            }

            using (var context = new MikiContext())
            {
                User user = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                if (user == null)
                {
                    return;
                }
                user.AvatarUrl = e.Author.Id.ToString();
                await context.SaveChangesAsync();
            }

            IDiscordEmbed embed = Utils.Embed;

            embed.Title       = "👌 OKAY";
            embed.Description = e.GetResource("sync_success", e.GetResource("term_avatar"));
            await embed.QueueToChannel(e.Channel);
        }
Пример #25
0
        public async Task DumpShards(EventContext e)
        {
            IDiscordEmbed embed = Utils.Embed;

            embed.Title = "Shards";

            foreach (IShard c in Bot.Instance.Shards)
            {
                embed.Description += $"`Shard {c.Id.ToString().PadRight(2)}` | `State: {c.ConnectionState} Ping: {c.Latency} Guilds: {c.Guilds.Count}`";
            }

            embed.QueueToChannel(e.Channel);

            await Task.Yield();
        }
Пример #26
0
        public async Task IdentifyPasta(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong());

            if (string.IsNullOrWhiteSpace(e.arguments))
            {
                await Utils.ErrorEmbed(locale, e.GetResource("infopasta_error_no_arg"))
                .QueueToChannel(e.Channel.Id);

                return;
            }

            using (var context = new MikiContext())
            {
                GlobalPasta pasta = await context.Pastas.FindAsync(e.arguments);

                if (pasta == null)
                {
                    await Utils.ErrorEmbed(locale, e.GetResource("miki_module_pasta_error_null")).QueueToChannel(e.Channel);

                    return;
                }

                User creator = await context.Users.FindAsync(pasta.CreatorId);

                IDiscordEmbed b = Utils.Embed;

                b.SetAuthor(pasta.Id.ToUpper(), "", "");
                b.Color = new Color(47, 208, 192);

                if (creator != null)
                {
                    b.AddInlineField(e.GetResource("miki_module_pasta_identify_created_by"), $"{ creator.Name} [{creator.Id}]");
                }

                b.AddInlineField(e.GetResource("miki_module_pasta_identify_date_created"), pasta.CreatedAt.ToShortDateString());

                b.AddInlineField(e.GetResource("miki_module_pasta_identify_times_used"), pasta.TimesUsed.ToString());

                VoteCount v = await pasta.GetVotesAsync(context);

                b.AddInlineField(e.GetResource("infopasta_rating"), $"⬆️ { v.Upvotes} ⬇️ {v.Downvotes}");

                await b.QueueToChannel(e.Channel);
            }
        }
Пример #27
0
        public async Task HugAsync(EventContext e)
        {
            string[] images = new string[]
            {
                "http://i.imgur.com/FvSnQs8.gif",
                "http://i.imgur.com/rXEq7oU.gif",
                "http://i.imgur.com/b6vVMQO.gif",
                "http://i.imgur.com/KJNTXm3.gif",
                "http://i.imgur.com/gn18SX8.gif",
                "http://i.imgur.com/SUdqF9w.gif",
                "http://i.imgur.com/7C36d39.gif",
                "http://i.imgur.com/ZOINyyw.gif",
                "http://i.imgur.com/Imxjcio.gif",
                "http://i.imgur.com/GNUeLdo.gif",
                "http://i.imgur.com/K52NZ36.gif",
                "http://i.imgur.com/683fWwC.gif",
                "http://i.imgur.com/0RgdLt4.gif",
                "http://i.imgur.com/jxPPkM8.gif",
                "http://i.imgur.com/oExwffx.gif",
                "http://i.imgur.com/pCZpL5h.gif",
                "http://i.imgur.com/GvQOwuy.gif",
                "http://i.imgur.com/cLHRyeB.gif",
                "http://i.imgur.com/FVbzx1A.gif",
                "http://i.imgur.com/gMLlFNC.gif",
                "http://i.imgur.com/FOdbhav.gif",
                "http://i.imgur.com/CEkg7K3.gif",
                "http://i.imgur.com/MrEMpE6.gif",
                "http://i.imgur.com/Y9sMTP4.gif"
            };

            Random r = new Random();

            IDiscordEmbed embed = Utils.Embed;

            if (e.arguments.Length > 0)
            {
                embed.Title = $"{e.Author.Username} hugs {e.message.RemoveMentions(e.arguments)}";
            }
            else
            {
                embed.Title = $"{e.message.Bot.Username} hugs {e.Author.Username}";
            }
            embed.ImageUrl = images[r.Next(0, images.Length)];

            await embed.QueueToChannel(e.Channel);
        }
Пример #28
0
        public async Task StatsAsync(EventContext e)
        {
            TimeSpan timeSinceStart = DateTime.Now.Subtract(Program.timeSinceStartup);

            IDiscordEmbed embed = Utils.Embed;

            embed.Title       = "⚙️ Miki stats";
            embed.Description = e.GetResource("stats_description");
            embed.Color       = new IA.SDK.Color(0.3f, 0.8f, 1);

            embed.AddInlineField($"🖥️ {e.GetResource("discord_servers")}", Bot.instance.Client.Guilds.Count.ToString());
            embed.AddInlineField("💬 " + e.GetResource("term_commands"), Bot.instance.Events.CommandsUsed().ToString());
            embed.AddInlineField("⏰ Uptime", timeSinceStart.ToTimeString(e.Channel.GetLocale()));
            embed.AddInlineField("More info", "https://p.datadoghq.com/sb/01d4dd097-08d1558da4");

            await embed.QueueToChannel(e.Channel);
        }
Пример #29
0
        public async Task SearchUser(EventContext e)
        {
            string[]                 arg   = e.arguments.Split(' ');
            IDiscordEmbed            embed = Utils.Embed;
            RocketLeagueSearchResult user  = await api.SearchUsersAsync(arg[0], (arg.Length >= 2)?int.Parse(arg[1]) : 0);

            embed.Title = $"Found {user.TotalResults} users with the name `{arg[0]}`";
            embed.CreateFooter();
            embed.Footer.Text = $"Page {user.Page} of ${(int)Math.Ceiling((double)user.TotalResults / user.MaxResultsPerPage)}";

            List <string> names = new List <string>();

            user.Data.ForEach(z => { names.Add(z.DisplayName); });

            embed.Description = string.Join(", ", names);

            embed.QueueToChannel(e.Channel);
        }
Пример #30
0
        public async Task SteamGameAsync(EventContext context)
        {
            DateTime requestStart = DateTime.Now;

            string[] args = context.arguments.Split(' ');

            IDiscordEmbed embed = Utils.Embed;

            embed.SetAuthor("Steam Game", steamAuthorIcon, "");

            SteamGameInfo gameInfo = await steam.GetGameInfo(args[0]);

            embed.SetDescription(gameInfo.Name);
            embed.SetThumbnailUrl(gameInfo.HeaderImage);

            embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", "");
            embed.QueueToChannel(context.Channel);
        }