Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        private Task Client_Ready()
        {
            Logger.Information("Client Ready event fired.");

            foreach (var guildId in inactivityService.Model.GuildInactivityMessage.Keys)
            {
                inactivityService.SetupInactivityReaction(guildId);
            }

            foreach (var guildId in inactivityService.Model.GuildMemberUpdateEvents.Keys)
            {
                inactivityService.SetupGuildMemberUpdated(guildId);
            }

            foreach (var guildId in communityApplicationService.Model.GuildApplicationMessage.Keys)
            {
                communityApplicationService.SetupApplications(guildId);
            }

            return(Task.CompletedTask);
        }