Пример #1
0
        public SubchannelService(string id)
        {
            GlobalMessenger.RegisterReceiver(id, (type, param) =>
            {
                CommandContext ctx = null;
                string response    = null;

                switch (type)
                {
                case "CreateChannel":
                    if (param is CommandContextAdv <Tuple <string, string> > ctxCreate &&
                        ctxCreate.Context.Guild != null)
                    {
                        ctx            = ctxCreate.Context;
                        string name    = ctxCreate.Argument.Item1;
                        string subject = ctxCreate.Argument.Item2;

                        response = CreateChannel(ctx.Guild, name, subject);
                    }
                    break;

                case "ListChannels":
                    if (param is CommandContextAdv ctxList &&
                        ctxList.Context.Guild != null)
                    {
                        ctx      = ctxList.Context;
                        response = ListChannels(ctx.Guild);
                    }
                    break;
Пример #2
0
        public KeywordService(string id, string botId)
        {
            m_manager = new KeywordManager(id);

            GlobalMessenger.RegisterReceiver(botId, (type, param) =>
            {
                if (type == "NewMessage" && param is MessageCreateEventArgs e)
                {
                    string msg = e.Message.Content;

                    // 서버 메세지이며
                    // 봇이 아니고
                    // 멘션이 없으면
                    if (e.Guild != null && !e.Channel.IsPrivate &&
                        !e.Author.IsBot &&
                        !e.MentionedUsers.Any())
                    {
                        ulong userId    = e.Author.Id;
                        ulong channelId = e.Channel.Id;

                        // 자기 자신은 제외하고 해당 채널을 볼 권한이 있는 사람만 필터링.
                        var keywordUsers = from keywordUser in m_manager.CheckKeywordIn(msg)
                                           where userId != keywordUser &&
                                           e.Channel.PermissionsFor(e.Guild.GetMemberAsync(keywordUser).Result).HasPermission(Permissions.AccessChannels)
                                           select keywordUser;

                        lock (m_syncQueue)
                        {
                            string noti = $"[{e.Guild.Name} : {e.Channel.Name}] {e.Author.Username}\n\"{msg.Trim()}\"";
                            foreach (ulong targetUser in keywordUsers)
                            {
                                m_queue.Add((e.Guild, targetUser, noti));
                            }
Пример #3
0
        public ProfileService(string id, string botId)
        {
            GlobalMessenger.RegisterReceiver(botId, (type, param) =>
            {
                if (type == "NewMessage" && param is MessageCreateEventArgs e)
                {
                    if (e.Guild != null)
                    {
                        EarnExp(e.Author.Id, e.Channel.Name, e.Message.Content);
                    }
                }
            });

            GlobalMessenger.RegisterReceiver(id, (type, param) =>
            {
                switch (type)
                {
                case "ShowProfile":
                    if (param is CommandContextAdv <Tuple <string> > ctxShow)
                    {
                        ShowProfile(ctxShow.Context);
                    }
                    break;

                case "EditProfile":
                    if (param is CommandContextAdv <Tuple <string> > ctxEdit)
                    {
                        EditProfile(ctxEdit.Context, ctxEdit.Arguments.Item1);
                    }
                    break;
                }
            });
        }
Пример #4
0
        public BotStatus(string id)
        {
            LoadStatusList();

            GlobalMessenger.RegisterReceiver(id, (type, param) =>
            {
                switch (type)
                {
                case "AddStatus":
                    AddStatus(param as string);
                    break;

                case "RemoveStatus":
                    RemoveStatus(param as string);
                    break;
                }
            });
        }
Пример #5
0
        public JudgeService(string id, string botId)
        {
            Root           = id;
            PunishmentFile = Path.Combine(id, "punish.dat");

            Directory.CreateDirectory(id);


            GlobalMessenger.RegisterReceiver(botId, (type, param) =>
            {
                if (type == "NewMessage" && param is MessageCreateEventArgs e)
                {
                    ulong userId = e.Author.Id;

                    // 서버 메세지이며 봇이 아니고 조용 채널도 아닌 경우만 확인.
                    if (e.Guild != null && !e.Author.IsBot && e.Channel.Name != "조용")
                    {
                        int punishTime = UpdateSpamGage(userId, e.Message.Timestamp);

                        // 스팸으로 판단되고 멤버가 스탭이 아니면 정지.
                        if (punishTime != 0)
                        {
                            // NOTE: 잦은 디스코드 API 호출을 피하기 위해 다중 if로 분리.

                            var member = e.Guild.GetMemberAsync(userId).Result;

                            if (member.Roles.Count() > 0 &&
                                member.Roles.All(role => role.Name != "스탭"))
                            {
                                m_executionQue.Enqueue(Tuple.Create(userId, punishTime));

                                string timeText = TimeToText(punishTime);
                                e.Message.RespondAsync($"{e.Author.Mention}님 도배로 {timeText} 정지입니다.").Wait();
                            }
                        }
                    }
                }
            });

            GlobalMessenger.RegisterReceiver(id, (type, param) =>
            {
                switch (type)
                {
                case "PunishUser":
                    if (param is CommandContextAdv <Tuple <int> > ctxPunish)
                    {
                        var ctx   = ctxPunish.Context;
                        var users = ctx.Message.MentionedUsers;

                        foreach (var user in users)
                        {
                            PunishUser(ctx.Client, user.Id, ctxPunish.Arguments.Item1);
                        }
                    }
                    break;

                case "ReleaseUser":
                    if (param is CommandContextAdv <Tuple <string> > ctxRelease)
                    {
                        var ctx   = ctxRelease.Context;
                        var users = ctx.Message.MentionedUsers;

                        foreach (var user in users)
                        {
                            ReleaseUser(ctx.Client, user.Id);
                        }
                    }
                    break;
                }
            });
        }
Пример #6
0
        public JudgeService(string id, string botId)
        {
            Root           = id;
            PunishmentFile = Path.Combine(id, "punish.dat");

            Directory.CreateDirectory(id);


            GlobalMessenger.RegisterReceiver(botId, (type, param) =>
            {
                if (type == "NewMessage" && param is MessageCreateEventArgs e)
                {
                    // 서버 메세지이며 봇이 아닌 경우만 확인.
                    if (e.Guild != null && !e.Author.IsBot)
                    {
                        ulong userId    = e.Author.Id;
                        ulong channelId = e.Channel.Id;

                        int punishTime = UpdateSpamGage(userId, channelId, e.Message.Timestamp);

                        // 스팸으로 판단되고 멤버가 역할이 있고 스탭이 아니면 정지.
                        if (punishTime != 0)
                        {
                            // NOTE: 잦은 디스코드 API 호출을 피하기 위해 다중 if로 분리.

                            var member = e.Guild.GetMemberAsync(userId).Result;

                            if (member.Roles.Count() > 0 &&
                                member.Roles.All(role => role.Id != DiscordConstants.StaffRoleId))
                            {
                                // 정지 예정 큐에 넣음.
                                m_executionQue.Enqueue(Tuple.Create(userId, punishTime));
                            }
                        }
                    }
                }
            });

            GlobalMessenger.RegisterReceiver(id, (type, param) =>
            {
                switch (type)
                {
                case "PunishUser":
                    if (param is CommandContextAdv <int> ctxPunish)
                    {
                        var ctx   = ctxPunish.Context;
                        var users = ctx.Message.MentionedUsers;

                        foreach (var user in users)
                        {
                            PunishUser(ctx.Client, user.Id, ctxPunish.Argument);
                        }
                    }
                    break;

                case "ReleaseUser":
                    if (param is CommandContextAdv ctxRelease)
                    {
                        var ctx   = ctxRelease.Context;
                        var users = ctx.Message.MentionedUsers;

                        foreach (var user in users)
                        {
                            ReleaseUser(ctx.Client, user.Id);
                        }
                    }
                    break;
                }
            });
        }