Exemple #1
0
        private Task OnUpdateGuilds(IDiscordGuild g)
        {
            MikiApplication bot = MikiApplication.Instance;

            //DiscordSocketClient client = bot.Client.GetShardFor(g);
            //await countLib.PostStats(client.ShardId, client.Guilds.Count);
            return(Task.CompletedTask);
        }
        public AchievementManager(MikiApplication bot)
        {
            this.bot = bot;

            AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) =>
            {
                if (await provider.IsEnabled(Global.RedisClient, c.Id))
                {
                    LevelPacket p = new LevelPacket()
                    {
                        discordUser    = await(c as IDiscordGuildChannel).GetUserAsync(u.Id),
                        discordChannel = c,
                        level          = l,
                    };
                    await OnLevelGained?.Invoke(p);
                }
            };

            AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) =>
            {
                if (await provider.IsEnabled(Global.RedisClient, msg.ChannelId))
                {
                    TransactionPacket p = new TransactionPacket()
                    {
                        discordUser    = msg.Author,
                        discordChannel = await msg.GetChannelAsync(),
                        giver          = u1,
                        receiver       = u2,
                        amount         = amount
                    };

                    await OnTransaction?.Invoke(p);
                }
            };

            bot.GetAttachedObject <EventSystem>().GetCommandHandler <SimpleCommandHandler>().OnMessageProcessed += async(e, m, t) =>
            {
                CommandPacket p = new CommandPacket()
                {
                    discordUser    = m.Author,
                    discordChannel = await m.GetChannelAsync(),
                    message        = m,
                    command        = e,
                    success        = true
                };
                await OnCommandUsed?.Invoke(p);
            };
        }
Exemple #3
0
        public AccountManager(MikiApplication bot)
        {
            OnGlobalLevelUp += (a, e, l) =>
            {
                DogStatsd.Counter("levels.global", l);
                return(Task.CompletedTask);
            };
            OnLocalLevelUp += async(a, e, l) =>
            {
                DogStatsd.Counter("levels.local", l);

                var  guild   = await(e as IDiscordGuildChannel).GetGuildAsync();
                long guildId = guild.Id.ToDbLong();

                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();

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

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

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

                    LocaleInstance instance = await Locale.GetLanguageInstanceAsync(e.Id);

                    EmbedBuilder embed = new EmbedBuilder()
                    {
                        Title       = instance.GetString("miki_accounts_level_up_header"),
                        Description = instance.GetString("miki_accounts_level_up_content", $"{a.Username}#{a.Discriminator}", l),
                        Color       = new Color(1, 0.7f, 0.2f)
                    };

                    if (rolesObtained.Count > 0)
                    {
                        var roles = await guild.GetRolesAsync();

                        var guildUser = await guild.GetMemberAsync(a.Id);

                        if (guildUser != null)
                        {
                            foreach (var role in rolesObtained)
                            {
                                var r = roles.FirstOrDefault(x => x.Id == (ulong)role.RoleId);

                                if (r != null)
                                {
                                    await guildUser.AddRoleAsync(r);
                                }
                            }
                        }

                        embed.AddInlineField("Rewards",
                                             string.Join("\n", rolesObtained.Select(x => $"New Role: **{roles.FirstOrDefault(z => z.Id.ToDbLong() == x.RoleId).Name}**")));
                    }

                    embed.ToEmbed().QueueToChannel(e);
                }
            };

            //bot.Discord.Guild += Client_GuildUpdated;
            bot.Discord.GuildMemberCreate += Client_UserJoined;
            bot.Discord.MessageCreate     += CheckAsync;
        }
Exemple #4
0
 public ServerCountModule(Module m, MikiApplication b)
 {
     m.JoinedGuild = OnUpdateGuilds;
     m.LeftGuild   = OnUpdateGuilds;
     //	countLib = new CountLib(ConnectionString);
 }
Exemple #5
0
 public InternalModule(Module module, MikiApplication bot)
 {
 }