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; }
public override IEnumerator PerformFirstPass() { InactivityService inactivityService = Service.Get <GameObject>().AddComponent <InactivityService>(); inactivityService.InactivityTimeoutSeconds = InactivityTimeoutSeconds; Service.Set(inactivityService); yield break; }
public async Task MainAsync() { _client = new DiscordSocketClient(new DiscordSocketConfig { #if DEBUG LogLevel = LogSeverity.Debug, #elif RELEASE LogLevel = LogSeverity.Info, #endif MessageCacheSize = 50, AlwaysDownloadUsers = true, DefaultRetryMode = RetryMode.AlwaysRetry, }); _commands = new CommandService(new CommandServiceConfig { #if DEBUG LogLevel = LogSeverity.Debug, #elif RELEASE LogLevel = LogSeverity.Info, #endif CaseSensitiveCommands = false, IgnoreExtraArgs = true, }); using var services = ConfigureServices(); Logger = services.GetRequiredService <LoggingService>().Logger; var configSerivce = services.GetRequiredService <ConfigService>(); var client = services.GetRequiredService <DiscordSocketClient>(); var config = await configSerivce.LoadJsonAsync(ConfigService.configFileName); if (config == null) { Logger.Error("No Config was found."); return; } client.Ready += Client_Ready; var baseService = services.GetRequiredService <BaseService>(); await baseService.Model.LoadJsonAsync(BaseModel.baseFileName); inactivityService = services.GetRequiredService <InactivityService>(); await inactivityService.Model.LoadJsonAsync(InactivityModel.inactivityFileName); communityApplicationService = services.GetRequiredService <CommunityApplicationService>(); await communityApplicationService.Model.LoadJsonAsync(CommunityApplicationModel.communityApplicationFileName); await client.LoginAsync(TokenType.Bot, config.Token); await client.StartAsync(); await services.GetRequiredService <CommandHandlingService>().InitializeAsync(); await Task.Delay(-1); }
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); }
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; }
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; }