示例#1
0
        public async Task SetInactiveEmoji(string emoji)
        {
            CultureInfo culture = BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            if (emoji == null || string.IsNullOrWhiteSpace(emoji))
            {
                await ReplyAsync(Inactivity.Emoji_NoSpecified);

                return;
            }

            if (emoji.Contains("<", StringComparison.InvariantCultureIgnoreCase) || emoji.Contains(">", StringComparison.InvariantCultureIgnoreCase))
            {
                await ReplyAsync(Inactivity.Emoji_Custom);

                return;
            }

            ulong guildId = Context.Guild.Id;

            if (InactivityModel.GuildInactiveEmoji.ContainsKey(guildId))
            {
                InactivityModel.GuildInactiveEmoji[guildId] = emoji;
            }
            else
            {
                InactivityModel.GuildInactiveEmoji.Add(guildId, emoji);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(string.Format(culture, Inactivity.Emoji_Success, "Inactive", emoji));
        }
示例#2
0
        public async Task RemoveRaids([Remainder] List <IRole> raids)
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (!InactivityModel.GuildRaidRoles.ContainsKey(guildId))
            {
                await ReplyAsync(Inactivity.GetRaid_NoRaids);

                return;
            }

            if (raids == null || raids.Count <= 0)
            {
                await ReplyAsync(Inactivity.SetRaid_NotFound);

                return;
            }

            var raidCollection = InactivityModel.GuildRaidRoles[guildId];

            foreach (var raid in raids.Select(r => r.Id))
            {
                raidCollection.Remove(raid);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.RemoveRaid_Success);
        }
示例#3
0
        public async Task InactivityAsync()
        {
            CultureInfo culture = BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            await Context.Message.DeleteAsync();

            ulong guildId = Context.Guild.Id;

            InactivityModel.GuildDestinationChannel.TryGetValue(guildId, out var destChannel);
            if (destChannel <= 0)
            {
                await ReplyAsync(Inactivity.Inactivity_MissingChannel);

                return;
            }

            InactivityModel.GuildInactivityRole.TryGetValue(guildId, out var role);
            if (role <= 0)
            {
                await ReplyAsync(Inactivity.Inactivity_MissingRole);

                return;
            }

            InactivityModel.GuildActiveEmoji.TryGetValue(guildId, out var activeEmoji);
            InactivityModel.GuildInactiveEmoji.TryGetValue(guildId, out var inactiveEmoji);

            if (string.IsNullOrWhiteSpace(activeEmoji))
            {
                activeEmoji = "\u25B6";
                InactivityModel.GuildActiveEmoji.Add(guildId, activeEmoji);
            }

            if (string.IsNullOrWhiteSpace(inactiveEmoji))
            {
                inactiveEmoji = "\u23F8\uFE0F";
                InactivityModel.GuildInactiveEmoji.Add(guildId, inactiveEmoji);
            }

            var message = await ReplyAsync(string.Format(culture, Inactivity.Inactivity_Message, inactiveEmoji, activeEmoji));

            await message.AddReactionsAsync(new[] { new Emoji(inactiveEmoji), new Emoji(activeEmoji) });

            if (InactivityModel.GuildInactivityMessage.ContainsKey(guildId))
            {
                InactivityModel.GuildInactivityMessage[guildId] = message.Id;
            }
            else
            {
                InactivityModel.GuildInactivityMessage.Add(guildId, message.Id);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            InactivityService.SetupInactivityReaction(guildId);

            return;
        }
示例#4
0
        public async Task SetInactiveRole(IRole role)
        {
            BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            if (role == null)
            {
                await ReplyAsync(Inactivity.SetRole_NoRole);

                return;
            }

            if (InactivityModel.GuildInactivityRole.ContainsKey(Context.Guild.Id))
            {
                InactivityModel.GuildInactivityRole[Context.Guild.Id] = role.Id;
            }
            else
            {
                InactivityModel.GuildInactivityRole.Add(Context.Guild.Id, role.Id);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.SetRole_Success);

            return;
        }
示例#5
0
        public async Task SetChannelAsync(ITextChannel channel)
        {
            BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            if (channel == null)
            {
                await ReplyAsync(Inactivity.SetChannel_NoChannel);

                return;
            }

            if (InactivityModel.GuildDestinationChannel.ContainsKey(channel.GuildId))
            {
                InactivityModel.GuildDestinationChannel[channel.GuildId] = channel.Id;
            }
            else
            {
                InactivityModel.GuildDestinationChannel.Add(channel.GuildId, channel.Id);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.SetChannel_Success);

            return;
        }
示例#6
0
        public InactivityService(DiscordSocketClient client, BaseService baseService, LoggingService loggingService)
        {
            if (loggingService == null)
            {
                throw new ArgumentNullException(nameof(loggingService));
            }

            Client      = client ?? throw new ArgumentNullException(nameof(client));
            BaseService = baseService ?? throw new ArgumentNullException(nameof(baseService));
            Logger      = loggingService.Logger;

            ReactionAddedPointers      = new Dictionary <ulong, Func <Cacheable <IUserMessage, ulong>, ISocketMessageChannel, SocketReaction, Task> >();
            GuildMemberUpdatedPointers = new Dictionary <ulong, Func <SocketGuildUser, SocketGuildUser, Task> >();
            Model        = new InactivityModel();
            OngoingUsers = new List <ulong>();
        }
示例#7
0
        public async Task CancleInactivityReaction()
        {
            BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            InactivityService.CancelInactivityReaction(guildId);

            InactivityModel.GuildInactivityMessage.TryGetValue(guildId, out ulong messageId);
            InactivityModel.GuildInactivityMessage.Remove(guildId);
            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            if (messageId > 0)
            {
                foreach (var channel in Context.Guild.TextChannels)
                {
                    var botUser            = Context.Guild.GetUser(Context.Client.CurrentUser.Id);
                    var channelPermissions = botUser.GetPermissions(channel);
                    if (channelPermissions.ReadMessageHistory && channelPermissions.ManageMessages)
                    {
                        var message = await channel.GetMessageAsync(messageId);

                        if (message == null)
                        {
                            continue;
                        }

                        await message.DeleteAsync();

                        await ReplyAsync(Inactivity.Cancel_Success);

                        return;
                    }
                }

                await ReplyAsync(Inactivity.Cancel_MissingPermissions);

                return;
            }

            await ReplyAsync(Inactivity.Cancel_MessageNotFound);
        }
示例#8
0
        public async Task SetRaid(IRole raid)
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (raid == null)
            {
                await ReplyAsync(Inactivity.SetRaid_NotFound);

                return;
            }

            if (InactivityModel.GuildRaidRoles.ContainsKey(guildId))
            {
                List <ulong> roles = InactivityModel.GuildRaidRoles[guildId];
                if (roles == null)
                {
                    InactivityModel.GuildRaidRoles[guildId] = new List <ulong>();
                }
                else if (roles.Contains(raid.Id))
                {
                    await ReplyAsync(Inactivity.SetRaid_AlreadyExisting);

                    return;
                }

                InactivityModel.GuildRaidRoles[guildId].Add(raid.Id);
            }
            else
            {
                List <ulong> raidRoles = new List <ulong> {
                    raid.Id
                };
                InactivityModel.GuildRaidRoles.Add(guildId, raidRoles);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.SetRaid_Success);
        }
示例#9
0
        public async Task StipGuildMemberUpdateEvent()
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (InactivityModel.GuildMemberUpdateEvents.ContainsKey(guildId))
            {
                InactivityModel.GuildMemberUpdateEvents[guildId] = false;
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            InactivityService.RemoveGuildMemberUpdated(guildId);

            await ReplyAsync(Inactivity.GuildMemberUpdated_Stop);

            return;
        }
示例#10
0
        public async Task StartGuildMemberUpdateEvents()
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (!InactivityModel.GuildInactivityRole.ContainsKey(guildId))
            {
                await ReplyAsync(Inactivity.Inactivity_MissingRole);

                return;
            }

            if (!InactivityModel.GuildDestinationChannel.ContainsKey(guildId))
            {
                await ReplyAsync(Inactivity.Inactivity_MissingChannel);

                return;
            }

            if (InactivityModel.GuildMemberUpdateEvents.ContainsKey(guildId))
            {
                InactivityModel.GuildMemberUpdateEvents[guildId] = true;
            }
            else
            {
                InactivityModel.GuildMemberUpdateEvents.Add(guildId, true);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            InactivityService.SetupGuildMemberUpdated(guildId);

            await ReplyAsync(Inactivity.GuildMemberUpdated_Start);

            return;
        }
示例#11
0
        public async Task SetInactiveRole([Remainder] string role)
        {
            BaseService.GetGuildCulture(Context.Guild.Id);

            await Context.Channel.TriggerTypingAsync();

            if (string.IsNullOrWhiteSpace(role))
            {
                await ReplyAsync(Inactivity.SetRole_NoRole);

                return;
            }

            var guildRole = Context.Guild.Roles.FirstOrDefault(r => r.Name.Equals(role, StringComparison.InvariantCultureIgnoreCase));

            if (guildRole == null)
            {
                await ReplyAsync(Inactivity.SetRole_RoleNotFound);

                return;
            }

            if (InactivityModel.GuildInactivityRole.ContainsKey(Context.Guild.Id))
            {
                InactivityModel.GuildInactivityRole[Context.Guild.Id] = guildRole.Id;
            }
            else
            {
                InactivityModel.GuildInactivityRole.Add(Context.Guild.Id, guildRole.Id);
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.SetRole_Success);

            return;
        }
示例#12
0
        public async Task RemoveRaid(IRole raid)
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (!InactivityModel.GuildRaidRoles.ContainsKey(guildId))
            {
                await ReplyAsync(Inactivity.GetRaid_NoRaids);

                return;
            }

            if (raid == null)
            {
                await ReplyAsync(Inactivity.SetRaid_NotFound);

                return;
            }

            var raidCollection = InactivityModel.GuildRaidRoles[guildId];

            if (!raidCollection.Contains(raid.Id))
            {
                await ReplyAsync(Inactivity.RemoveRaid_RaidNotFound);

                return;
            }

            raidCollection.Remove(raid.Id);
            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.RemoveRaid_Success);
        }
示例#13
0
        public async Task SetRaid([Remainder] List <IRole> raids)
        {
            await Context.Channel.TriggerTypingAsync();

            ulong guildId = Context.Guild.Id;

            BaseService.GetGuildCulture(guildId);

            if (raids == null || raids.Count <= 0)
            {
                await ReplyAsync(Inactivity.SetRaid_NotFound);

                return;
            }

            if (InactivityModel.GuildRaidRoles.ContainsKey(guildId))
            {
                List <ulong> roles = InactivityModel.GuildRaidRoles[guildId];
                if (roles == null)
                {
                    InactivityModel.GuildRaidRoles[guildId] = new List <ulong>();
                }

                var newRoles = raids.Select(r => r.Id).Except(roles);

                InactivityModel.GuildRaidRoles[guildId].AddRange(newRoles);
            }
            else
            {
                InactivityModel.GuildRaidRoles.Add(guildId, raids.Select(r => r.Id).ToList());
            }

            await InactivityModel.SaveJsonAsync(InactivityModel.inactivityFileName);

            await ReplyAsync(Inactivity.SetRaid_Success);
        }