public async Task ResetServer() { IUserMessage message = await ReplyAsync("Reseting..."); DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { server.Users = new List <ServerUser>(); foreach (SocketGuildUser user in server.Guild.Users) { if (server.Users.Find(x => x.userID == user.Id) == null) { server.Users.Add(new ServerUser(user)); } } } else { await message.ModifyAsync(x => x.Content = "I dont think i did it right."); } server.SaveData(); server.LoadData(); await message.ModifyAsync(x => x.Content = "L-Like this?"); }
public async Task ClearBadStuff(SocketGuildUser inputUser) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { ServerUser user = server.Users.Find(x => x.userID == inputUser.Id); if (user != null) { await ReplyAsync("Has removed all the bad stuff " + user.username + " has done!"); user.FirstSwearWithinTime = user.FirstSwearWithinTime.AddDays(-10); user.SwearsWithinTime = 0; user.isMuted = false; user.messageIn1Second = 0; user.FirstSpamWithinHour = DateTime.Now.AddYears(-1); user.spamTimesWithinHour = 0; user.bigTextSpamWithinTime = 0; user.BigTextSpamWithin20Sec = DateTime.Now.AddYears(-1); if (server.MuteRole != null) { SocketGuildUser guildUser = server.Guild.Users.ToList().Find(x => x.Id == user.userID); if (guildUser != null) { await guildUser.RemoveRoleAsync(server.MuteRole); } } server.SaveData(); } } }
public async Task SetMuteRole(string parameter) { if (((SocketGuildUser)Context.User).GuildPermissions.Has(Discord.GuildPermission.ManageRoles)) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { SocketRole FoundRole = null; foreach (SocketRole role in Context.Guild.Roles) { if (role.Name == parameter) { FoundRole = role; break; } } if (FoundRole != null) { server.MuteRole = FoundRole; server.SaveData(); await ReplyAsync("Mute Role set to: " + server.MuteRole.Name + "!"); } else { await ReplyAsync("There is no role such as " + parameter); } } } else { await ReplyAsync("You dont have sufficient permissions to set the mute role!"); } }
public async Task RemoveSwear(string word) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { if (server.swearJar != null) { if (server.swearJar.Find(x => x == word) != null) { server.swearJar.Remove(word); server.SaveData(); await ReplyAsync("The word has now been removed from the swearjar!"); } else { await ReplyAsync("The word is not in the list"); } } else { await ReplyAsync("The word is not in the list"); } } }
public async Task AddSwear(string word) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { if (server.swearJar == null) { server.swearJar = new List <string>(); } if (server.swearJar.Find(x => x == word) == null) { server.swearJar.Add(word); await PermissionWrapper.DeleteMessage(Context.Message); server.SaveData(); IUserMessage addedMessage = await ReplyAsync("The word has been added in the swearjar"); await Task.Delay(2500); } else { await PermissionWrapper.DeleteMessage(Context.Message); IUserMessage addedMessage = await ReplyAsync("The word is already in the swearjar"); await Task.Delay(2500); } } }
public async Task CreateVoiceChannelForRole(string channelName) { RestRole newRole = await Context.Guild.CreateRoleAsync(channelName); RestTextChannel textChannel = await Context.Guild.CreateTextChannelAsync(channelName); RestVoiceChannel voiceChannel = await Context.Guild.CreateVoiceChannelAsync(channelName); Discord.OverwritePermissions newRolePermission = new Discord.OverwritePermissions( readMessages: Discord.PermValue.Allow ); Discord.OverwritePermissions everyonePermission = new Discord.OverwritePermissions( readMessages: Discord.PermValue.Deny ); await textChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, everyonePermission); await textChannel.AddPermissionOverwriteAsync(newRole, newRolePermission); DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); server.voiceChannelRoles.Add(new VoiceChannelRole() { voiceChannelID = voiceChannel.Id, textChannelID = textChannel.Id, roleID = newRole.Id }); server.SaveData(); }
public static Task OnUserJoinedVC(SocketUser user, SocketVoiceState beforeState, SocketVoiceState afterState) { SocketGuildUser guildUser = user as SocketGuildUser; DiscordServer server = DiscordServer.GetServerFromID(guildUser.Guild.Id); if (afterState.VoiceChannel != null) { VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.voiceChannelID == afterState.VoiceChannel.Id); if (vcRole.roleID == 0) { return(Task.CompletedTask); } SocketRole role = server.Guild.GetRole(vcRole.roleID); if (role == null) { server.voiceChannelRoles.Remove(vcRole); server.SaveData(); return(Task.CompletedTask); } guildUser.AddRoleAsync(role); } if (beforeState.VoiceChannel != null) { VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.voiceChannelID == beforeState.VoiceChannel.Id); if (vcRole.roleID == 0) { return(Task.CompletedTask); } SocketRole role = server.Guild.GetRole(vcRole.roleID); if (role == null) { server.voiceChannelRoles.Remove(vcRole); server.SaveData(); return(Task.CompletedTask); } guildUser.RemoveRoleAsync(role); } return(Task.CompletedTask); }
public static Task CheckVoiceChannelOnDelete(SocketChannel channel) { if (channel is SocketVoiceChannel voiceChannel) { DiscordServer server = DiscordServer.GetServerFromID(voiceChannel.Guild.Id); VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.voiceChannelID == voiceChannel.Id); server.voiceChannelRoles.Remove(vcRole); SocketRole role = server.Guild.GetRole(vcRole.roleID); if (vcRole.voiceChannelID != 0) { SocketTextChannel textChannelDeletion = server.Guild.GetTextChannel(vcRole.textChannelID); if (textChannelDeletion != null) { textChannelDeletion.DeleteAsync(); } } if (role != null) { role.DeleteAsync(); } server.SaveData(); } if (channel is SocketTextChannel textChannel) { DiscordServer server = DiscordServer.GetServerFromID(textChannel.Guild.Id); VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.textChannelID == textChannel.Id); server.voiceChannelRoles.Remove(vcRole); SocketRole role = server.Guild.GetRole(vcRole.roleID); if (vcRole.voiceChannelID != 0) { SocketVoiceChannel voiceChannelDeletion = server.Guild.GetVoiceChannel(vcRole.voiceChannelID); if (voiceChannelDeletion != null) { voiceChannelDeletion.DeleteAsync(); } } if (role != null) { role.DeleteAsync(); } server.SaveData(); } return(Task.CompletedTask); }
public async Task SetWelcome(ISocketMessageChannel channel) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); server.WelcomeChannel = channel as SocketChannel; server.SaveData(); await ReplyAsync("Welcome channel set to: " + ((SocketTextChannel)server.WelcomeChannel).Mention + "!"); return; }
public void SaveAndLoad() { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { server.SaveData(); server.LoadData(); } else { Program.discordServers.Add(new DiscordServer(Context.Guild)); } }
public async Task AutoRole(string mode = "get", string parameter = "") { if (((SocketGuildUser)Context.User).GuildPermissions.Has(Discord.GuildPermission.ManageChannels)) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (mode == "get") { if (server.WelcomeRole != null) { await ReplyAsync("Current autorole is: " + server.WelcomeRole.Name + "!"); } else { await ReplyAsync("There is no role set."); } } else if (mode == "set") { SocketRole FoundRole = null; foreach (SocketRole role in Context.Guild.Roles) { if (role.Name == parameter) { FoundRole = role; break; } } if (FoundRole != null) { server.WelcomeRole = FoundRole; server.SaveData(); await ReplyAsync("Auto-Role set to: " + server.WelcomeRole.Name + "!"); } else { await ReplyAsync("There is no role such as " + parameter); } } } else { await ReplyAsync("You dont have sufficient permissions to set the welcome channel!"); } }
public async Task EnableSwearing(bool value = true) { if (((SocketGuildUser)Context.User).GuildPermissions.Has(Discord.GuildPermission.Administrator)) { DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id); if (server != null) { server.swearing = value; server.SaveData(); if (value) { await ReplyAsync("You can now swear as much as you want"); } else { await ReplyAsync("You wont be able to swear anymore!"); } } } }
public static async Task SwearChecker(SocketUserMessage message, DiscordServer server, ServerUser user) { if (server.swearing) { return; } var punctuation = message.Content.Where(Char.IsPunctuation).Distinct().ToArray(); var words = message.Content.Split().Select(x => x.Trim(punctuation)).ToList(); foreach (string swearWord in server.swearJar) { if (words.Find(x => x.ToLower().Contains(swearWord.ToLower())) != null) { await PermissionWrapper.DeleteMessage(message); user.Points -= 3; if (user.FirstSwearWithinTime.AddHours(1) > DateTime.Now) { user.SwearsWithinTime++; } else { user.SwearsWithinTime = 1; user.FirstSwearWithinTime = DateTime.Now; } if (user.SwearsWithinTime == 1 || user.SwearsWithinTime == 2) { await message.Channel.SendMessageAsync(Responses.GetRandomResponce(Responses.DontSwear) + message.Author.Mention); } else if (user.SwearsWithinTime == 3) { await message.Channel.SendMessageAsync(Responses.GetRandomResponce(Responses.WarningKickOut) + message.Author.Mention); } else if (user.SwearsWithinTime == 4) { await message.Channel.SendMessageAsync("I have now muted you for 5 minutes " + message.Author.Mention + ", this is your last chance."); user.isMuted = true; user.whenMuted = DateTime.Now; if (server.MuteRole != null) { await((SocketGuildUser)message.Author).AddRoleAsync(server.MuteRole); } } else if (user.SwearsWithinTime >= 5) { if (server.KickTimeStart.AddHours(1) > DateTime.Now) { server.PlayersKickedWithinTime++; } else { server.KickTimeStart = DateTime.Now; server.PlayersKickedWithinTime++; } if (!((SocketGuildUser)message.Author).GuildPermissions.Administrator) { await((SocketGuildUser)message.Author).KickAsync("For repeatedly swearing."); server.Users.Remove(server.Users.Find(x => x.userID == message.Author.Id)); } await message.Channel.SendMessageAsync("We have now kicked out: " + message.Author.Mention); if (server.PlayersKickedWithinTime >= 3) { if (File.Exists("Images/Reactions/hifumi_pale.png")) { await message.Channel.SendFileAsync("Images/Reactions/hifumi_pale.png"); } } } server.SaveData(); } } }