private async Task HandleUserJoinedAsync(SocketGuildUser socketUser) { var user = socketUser as IGuildUser; var dbGuild = await _guildRepository.GetGuildAsync(user.GuildId); if (dbGuild.NewUserRole != 0) { var role = user.Guild.GetRole(dbGuild.NewUserRole); if (role != null) { await user.AddRoleAsync(user.Guild.GetRole(dbGuild.NewUserRole)); } } var userDm = await user.GetOrCreateDMChannelAsync(); if (dbGuild.LockedDown == true) { await _text.SendAsync(userDm, $"The server you just joined is currently on lockdown. This means that you and all other new users will be banned every time you join until the server is unlocked."); await user.BanAsync(0, "Server on lockdown."); return; } if (dbGuild.WelcomeMessage != null || dbGuild.WelcomeMessage.Length > 0) { await _text.SendAsync(userDm, dbGuild.WelcomeMessage); } }
private Task HandleUserJoined(SocketGuildUser u) { return(Task.Run(async() => { Logger.Log(LogSeverity.Debug, $"Event", "User Joined"); if ((await _blacklistRepo.AllAsync()).Any(x => x.UserId == u.Id)) { try { await u.Guild.AddBanAsync(u); } catch { // Ignored. } } var user = u as IGuildUser; var dbGuild = await _guildRepo.GetGuildAsync(user.Guild.Id); var mutedRole = user.Guild.GetRole((dbGuild.MutedRoleId)); if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles && mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { await _RankHandler.HandleAsync(user, dbGuild, await _userRepo.GetUserAsync(user)); if (await _muteRepo.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null) { await user.AddRoleAsync(mutedRole); } } if (!string.IsNullOrWhiteSpace(dbGuild.WelcomeMessage)) { var channel = _client.GetChannel(dbGuild.WelcomeChannelId); if (channel != null) { try { await(channel as ITextChannel).SendAsync($"{u}, " + dbGuild.WelcomeMessage); } catch { // Ignored. } } else { try { var dmChannel = await u.CreateDMChannelAsync(); await dmChannel.SendAsync(dbGuild.WelcomeMessage); } catch { // Ignored. } } } })); }
public async Task InitializeAsync() { DbUser = await _userRepo.GetUserAsync(GUser); DbGuild = await _guildRepo.GetGuildAsync(Guild.Id); Gang = await _gangRepo.GetGangAsync(GUser); Prefix = DbGuild.Prefix; Cash = DbUser.Cash; }
private void Unmute(object stateObj) { Task.Run(async() => { List <Mute> collection = null; try { collection = await _muteRepository.AllAsync(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } foreach (var mute in collection) { if (DateTime.Now.Subtract(mute.MutedAt).TotalMilliseconds <= mute.MuteLength) { return; } try { var guild = await(_client as IDiscordClient).GetGuildAsync(mute.GuildId); var user = await guild.GetUserAsync(mute.UserId); var dbGuild = await _guildRepository.GetGuildAsync(guild.Id); var mutedRole = guild.GetRole(dbGuild.MutedRoleId); await user.RemoveRoleAsync(mutedRole); await _moderationService.ModLogAsync(dbGuild, guild, "Auto unmute", Configuration.UnmuteColor, string.Empty, null, user); await Task.Delay(500); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { await _muteRepository.DeleteAsync(mute); } } }); }
private void Unmute(object stateObj) { Task.Run(async() => { Logger.Log(LogSeverity.Debug, $"Timers", "Auto Unmute"); foreach (var mute in await _muteRepo.AllAsync()) { if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds > mute.MuteLength) { var guild = await(_client as IDiscordClient).GetGuildAsync(mute.GuildId); var user = await guild.GetUserAsync(mute.UserId); if (guild != null && user != null) { var guildData = await _guildRepo.GetGuildAsync(guild.Id); var mutedRole = guild.GetRole(guildData.MutedRoleId); if (mutedRole != null && user.RoleIds.Any(x => x == mutedRole.Id)) { var channel = await guild.GetTextChannelAsync(guildData.ModLogChannelId); ChannelPermissions?perms = null; var currentUser = await guild.GetCurrentUserAsync(); if (channel != null) { perms = currentUser.GetPermissions(channel as SocketTextChannel); } if (channel != null && currentUser.GuildPermissions.EmbedLinks && perms.Value.SendMessages && perms.Value.EmbedLinks) { await user.RemoveRoleAsync(mutedRole); var footer = new EmbedFooterBuilder() { IconUrl = "http://i.imgur.com/BQZJAqT.png", Text = $"Case #{guildData.CaseNumber}" }; var embedBuilder = new EmbedBuilder() { Color = new Color(12, 255, 129), Description = $"**Action:** Automatic Unmute\n**User:** {user} ({mute.UserId})", Footer = footer }.WithCurrentTimestamp(); await _guildRepo.ModifyAsync(guildData, x => x.CaseNumber++); await channel.SendMessageAsync(string.Empty, embed: embedBuilder); } } } await _muteRepo.RemoveMuteAsync(mute.UserId, mute.GuildId); } } }); }
public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _credentials = _serviceProvider.GetService <Credentials>(); _userRepo = _serviceProvider.GetService <UserRepository>(); _moderationService = serviceProvider.GetService <ModerationService>(); _guildRepo = _serviceProvider.GetService <GuildRepository>(); _gangRepo = _serviceProvider.GetService <GangRepository>(); var guildUser = context.User as IGuildUser; var DbUser = await _userRepo.GetUserAsync(guildUser); var DbGuild = await _guildRepo.GetGuildAsync(context.Guild.Id); foreach (var attribute in _attributes) { switch (attribute) { case Attributes.BotOwner: if (!_credentials.OwnerIds.Any(x => x == context.User.Id)) { return(PreconditionResult.FromError("Only an owner of this bot may use this command.")); } break; case Attributes.ServerOwner: if (context.Guild.OwnerId != guildUser.Id && DbGuild.ModRoles.ElementCount == 0) { return(PreconditionResult.FromError("Only the owners of this server may use this command.")); } else if (guildUser.Guild.OwnerId != context.User.Id && DbGuild.ModRoles != null && !guildUser.RoleIds.Any(x => DbGuild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 3))) { return(PreconditionResult.FromError("Only the owners of this server may use this command.")); } break; case Attributes.Admin: if (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount == 0) { return(PreconditionResult.FromError("The administrator permission is required to use this command.")); } else if (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount != 0 && !guildUser.RoleIds.Any(x => DbGuild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 2))) { return(PreconditionResult.FromError("The administrator permission is required to use this command.")); } break; case Attributes.Moderator: if (_moderationService.GetPermLevel(DbGuild, context.User as IGuildUser) == 0) { return(PreconditionResult.FromError("Only a moderator may use this command.")); } break; case Attributes.Nsfw: if (!DbGuild.Nsfw) { return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " + $"`{DbGuild.Prefix}ChangeNSFWSettings` command.")); } var nsfwChannel = await context.Guild.GetChannelAsync(DbGuild.NsfwChannelId); if (nsfwChannel != null && context.Channel.Id != DbGuild.NsfwChannelId) { return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}.")); } break; case Attributes.InGang: if (!await _gangRepo.InGangAsync(guildUser)) { return(PreconditionResult.FromError("You must be in a gang to use this command.")); } break; case Attributes.NoGang: if (await _gangRepo.InGangAsync(guildUser)) { return(PreconditionResult.FromError("You may not use this command while in a gang.")); } break; case Attributes.GangLeader: if ((await _gangRepo.GetGangAsync(guildUser)).LeaderId != context.User.Id) { return(PreconditionResult.FromError("You must be the leader of a gang to use this command.")); } break; case Attributes.Jump: if (DbUser.Cash < Config.JUMP_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.JUMP_REQUIREMENT.USD()}.")); } break; case Attributes.Steal: if (DbUser.Cash < Config.STEAL_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.STEAL_REQUIREMENT.USD()}.")); } break; case Attributes.Rob: if (DbUser.Cash < Config.ROB_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.ROB_REQUIREMENT.USD()}.")); } break; case Attributes.Bully: if (DbUser.Cash < Config.BULLY_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.BULLY_REQUIREMENT.USD()}.")); } break; case Attributes.FiftyX2: if (DbUser.Cash < Config.FIFTYX2_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.FIFTYX2_REQUIREMENT.USD()}.")); } break; default: return(PreconditionResult.FromError($"ERROR: The {attribute} attribute is not being handled!")); } } return(PreconditionResult.FromSuccess()); }
private void Unmute(object stateObj) { Task.Run(async() => { Logger.Log(LogSeverity.Debug, $"Timers", "Auto Unmute"); List <Mute> collection = null; try { collection = await _muteRepo.AllAsync(); } catch (Exception e) { Logger.Log(LogSeverity.Error, "Attempting to all async the mute repo.", e.StackTrace); } if (collection == null) { Logger.Log(LogSeverity.Error, "Collection is null", $"Stopping Auto Unmute"); return; } Logger.Log(LogSeverity.Debug, "Successfully loaded collection", $"Collection count: {collection.Count}"); foreach (var mute in collection) { if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds <= mute.MuteLength) { return; } Logger.Log(LogSeverity.Debug, "Mute is passed it's length", $"More information soon..."); try { var guild = await(_client as IDiscordClient).GetGuildAsync(mute.GuildId); Logger.Log(LogSeverity.Debug, "Mute Guild:", guild.Name + $" ({mute.GuildId})"); var user = await guild.GetUserAsync(mute.UserId); Logger.Log(LogSeverity.Debug, "Mute User:"******"{user} ({mute.UserId})"); var dbGuild = await _guildRepo.GetGuildAsync(guild.Id); Logger.Log(LogSeverity.Debug, "DbGuild Fetched", $"Mod Log Channel Id: {dbGuild.ModLogChannelId}"); var mutedRole = guild.GetRole(dbGuild.MutedRoleId); Logger.Log(LogSeverity.Debug, "Muted role fetched", mutedRole.Name + $" ({mutedRole.Id})"); await user.RemoveRoleAsync(mutedRole); Logger.Log(LogSeverity.Debug, "Successfully removed a role", $"Mute: {mute}"); var result = await _moderationService.TryModLogAsync(dbGuild, guild, "Automatic Unmute", new Color(12, 255, 129), string.Empty, null, user); Logger.Log(LogSeverity.Debug, "Mod log attempt", $"Succes: {result}"); await Task.Delay(500); } catch (Exception e) { Logger.Log(LogSeverity.Error, "Auto Unmute role removal", e.StackTrace); } finally { await _muteRepo.DeleteAsync(mute); Logger.Log(LogSeverity.Debug, "Mute entry deleted", "Passed it's length"); } } }); }
public async Task InitializeAsync() { DbGuild = await _guildRepo.GetGuildAsync(Guild.Id); DbUser = await _userRepo.GetUserAsync(GuildUser.Id, GuildUser.GuildId); }