コード例 #1
0
        public AchievementManager(MikiApp bot)
        {
            this.bot = bot;

            AccountManager.Instance.OnLocalLevelUp += async(u, c, l) =>
            {
                using (var db = new MikiContext())
                {
                    if (await provider.IsEnabled(MikiApp.Instance.GetService <ICacheClient>(), db, 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) =>
            {
                using (var db = new MikiContext())
                {
                    if (await provider.IsEnabled(MikiApp.Instance.GetService <ICacheClient>(), db, msg.ChannelId))
                    {
                        TransactionPacket p = new TransactionPacket()
                        {
                            discordUser    = msg.Author,
                            discordChannel = await msg.GetChannelAsync(),
                            giver          = u1,
                            receiver       = u2,
                            amount         = amount
                        };

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

            bot.GetService <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);
            };
        }
コード例 #2
0
ファイル: AchievementManager.cs プロジェクト: SnipeFrost/Miki
        public AchievementManager(IBot bot)
        {
            this.bot = bot;

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

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

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

            EventSystem.Instance.AddCommandDoneEvent(x =>
            {
                x.Name         = "--achievement-manager-command";
                x.processEvent = async(m, e, s, t) =>
                {
                    CommandPacket p = new CommandPacket()
                    {
                        discordUser    = m.Author,
                        discordChannel = m.Channel,
                        message        = m,
                        command        = e,
                        success        = s
                    };
                    await OnCommandUsed?.Invoke(p);
                };
            });
        }
コード例 #3
0
ファイル: AchievementManager.cs プロジェクト: wingertge/Miki
        public AchievementManager(Bot 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);
            };
        }
コード例 #4
0
ファイル: AchievementManager.cs プロジェクト: mugSans/Miki
        public AchievementManager(Bot bot)
        {
            this.bot = bot;

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

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

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

            bot.GetAttachedObject <EventSystem>().OnCommandDone += async(ex, e, m, t) =>
            {
                CommandPacket p = new CommandPacket()
                {
                    discordUser    = m.Author,
                    discordChannel = m.Channel,
                    message        = m,
                    command        = e,
                    success        = ex == null
                };
                await OnCommandUsed?.Invoke(p);
            };
        }
コード例 #5
0
        private AchievementManager(Bot bot)
        {
            this.bot = bot;

            AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) =>
            {
                LevelPacket p = new LevelPacket()
                {
                    discordUser    = await c.Guild.GetUserAsync(u.Id.FromDbLong()),
                    discordChannel = c,
                    account        = u,
                    level          = l,
                };
                await OnLevelGained?.Invoke(p);
            };
            AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) =>
            {
                TransactionPacket p = new TransactionPacket()
                {
                    discordUser    = msg.Author,
                    discordChannel = msg.Channel,
                    giver          = u1,
                    receiver       = u2,
                    amount         = amount
                };

                await OnTransaction?.Invoke(p);
            };

            bot.Client.MessageReceived += async(e) =>
            {
                if (OnMessageReceived == null)
                {
                    return;
                }

                MessageEventPacket p = new MessageEventPacket()
                {
                    message        = new RuntimeMessage(e),
                    discordUser    = new RuntimeUser(e.Author),
                    discordChannel = new RuntimeMessageChannel(e.Channel)
                };
                await OnMessageReceived?.Invoke(p);
            };
            bot.Client.UserUpdated += async(ub, ua) =>
            {
                UserUpdatePacket p = new UserUpdatePacket()
                {
                    discordUser = new RuntimeUser(ub),
                    userNew     = new RuntimeUser(ua)
                };
                await OnUserUpdate?.Invoke(p);
            };
            bot.Events.AddCommandDoneEvent(x =>
            {
                x.Name         = "--achievement-manager-command";
                x.processEvent = async(m, e, s) =>
                {
                    CommandPacket p = new CommandPacket()
                    {
                        discordUser    = m.Author,
                        discordChannel = m.Channel,
                        message        = m,
                        command        = e,
                        success        = s
                    };
                    await OnCommandUsed?.Invoke(p);
                };
            });
        }