public async Task RemoveSettings([Remainder] string settingName) { var allowedRoles = await GuildModRepository.ListByGuildId(Context.Guild.Id); var allowedRoleIds = allowedRoles.Select(r => r.RoleId); var socketGuildUser = Context.User as SocketGuildUser; if (!socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { await ReplyAsync("You don't have permission."); return; } //await ReplyAsync("Allowed"); var settingsPath = MMRService.GetSettingsPath(Context.Guild.Id, settingName); if (!File.Exists(settingsPath)) { await ReplyAsync("Setting does not exist."); return; } File.Delete(settingsPath); await ReplyAsync("Deleted settings."); }
public async Task AddMystery([Remainder] string categoryName) { var allowedRoles = await GuildModRepository.ListByGuildId(Context.Guild.Id); var allowedRoleIds = allowedRoles.Select(r => r.RoleId); var socketGuildUser = Context.User as SocketGuildUser; if (!socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { await ReplyNoTagAsync("You don't have permission."); return; } //await ReplyAsync("Allowed"); if (Context.Message.Attachments.Count != 1) { await ReplyNoTagAsync("Must attach one settings json file."); return; } var settingsFile = Context.Message.Attachments.Single(); if (settingsFile.Size > 10000) // kinda arbitrary { await ReplyNoTagAsync("File is too large."); return; } if (Path.GetExtension(settingsFile.Filename) != ".json") { await ReplyNoTagAsync("File must be a json file."); return; } var replacing = false; var mysteryPath = _mmrService.GetMysteryPath(Context.Guild.Id, categoryName, true); var settingPath = Path.Combine(mysteryPath, settingsFile.Filename); if (File.Exists(settingPath)) { replacing = true; } using (var client = new WebClient()) { await client.DownloadFileTaskAsync(new Uri(settingsFile.Url), settingPath); } await ReplyNoTagAsync($"{(replacing ? "Replaced" : "Added")} mystery setting."); }
public async Task Help() { var commands = new Dictionary <string, string>() { { "help", "See this help list." }, }; if (await TournamentChannelRepository.ExistsByChannelId(Context.Channel.Id)) { commands.Add("seed (<@user>){2,}", "Generate a seed. The patch and hashIcons will be sent in a direct message to the tagged users. The spoiler log will be sent to you."); } else { if (Context.IsPrivate) { commands.Add("seed", "Generate a seed."); } else { commands.Add("seed (<settingName>)?", "Generate a seed. Optionally provide a setting name."); commands.Add("mystery <categoryName>", "Generate a seed using a random setting from the <categoryName> mystery category."); } commands.Add("spoiler", "Retrieve the spoiler log for your last generated seed."); } if (!Context.IsPrivate && Context.User is SocketGuildUser socketGuildUser) { var allowedRoles = await GuildModRepository.ListByGuildId(Context.Guild.Id); var allowedRoleIds = allowedRoles.Select(r => r.RoleId); if (socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { commands.Add("add-settings <settingName>", "Upload a settings file and name it."); commands.Add("remove-settings <settingName>", "Remove a named setting."); } commands.Add("list-settings", "List the names of available settings."); commands.Add("get-settings <settingName>", "Get a setting file."); if (socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { commands.Add("add-mystery <categoryName>", "Upload a settings file and add it to the <categoryName> category."); commands.Add("remove-mystery <categoryName> <settingName>", "Remove <settingName> from the <categoryName> mystery category."); } commands.Add("list-mystery (<categoryName>)?", "List the names of available mystery categories, or list the settings within a mystery category."); commands.Add("get-mystery <categoryName> <settingName>", "Get the <settingName> setting from the <categoryName> mystery category."); } AddHelp(commands); await ReplyNoTagAsync("List of commands: (all commands begin with \"!mmr\")\n" + string.Join('\n', commands.Select(kvp => $"`{kvp.Key}` - {kvp.Value}"))); }
public async Task RemoveModRole(IRole role) { var guildMod = await GuildModRepository.Single(gm => gm.RoleId == role.Id && gm.GuildId == Context.Guild.Id); if (guildMod == null) { await ReplyAsync("Role is already not a mod role."); return; } await GuildModRepository.DeleteById(guildMod.Id); await ReplyAsync("Removed"); }
public async Task AddModRole(IRole role) { var guildMod = await GuildModRepository.Single(gm => gm.RoleId == role.Id && gm.GuildId == Context.Guild.Id); if (guildMod != null) { await ReplyAsync("Role is already a mod role."); return; } await GuildModRepository.Save(new GuildModEntity { GuildId = Context.Guild.Id, RoleId = role.Id, }); await ReplyAsync("Added"); }
public async Task Help() { var commands = new Dictionary <string, string>() { { "help", "See this help list." }, }; if (_tournamentChannels.Contains(Context.Channel.Id)) { commands.Add("seed (<@user>){2,}", "Generate a seed. The patch and hashIcons will be sent in a direct message to the tagged users. The spoiler log will be sent to you."); } else { if (Context.IsPrivate) { commands.Add("seed", "Generate a seed."); } else { commands.Add("seed (<settingName>)?", "Generate a seed. Optionally provide a setting name."); } commands.Add("spoiler", "Retrieve the spoiler log for your last generated seed."); } if (!Context.IsPrivate && Context.User is SocketGuildUser socketGuildUser) { if (socketGuildUser.GuildPermissions.Has(GuildPermission.Administrator)) { commands.Add("add-mod-role (<@role>)+", "Allow the tagged role(s) to use the setting commands."); commands.Add("remove-mod-role (<@role>)+", "Disallow the tagged role(s) from using the setting commands."); } var allowedRoles = await GuildModRepository.ListByGuildId(Context.Guild.Id); var allowedRoleIds = allowedRoles.Select(r => r.RoleId); if (socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { commands.Add("add-settings <settingName>", "Upload a settings file and name it."); commands.Add("remove-settings <settingName>", "Remove a named setting."); } commands.Add("list-settings", "List the names of available settings."); } await ReplyAsync("List of commands: (all commands begin with \"!mmr\")\n" + string.Join('\n', commands.Select(kvp => $"`{kvp.Key}` - {kvp.Value}"))); }
public async Task RemoveMystery(params string[] argument) { var allowedRoles = await GuildModRepository.ListByGuildId(Context.Guild.Id); var allowedRoleIds = allowedRoles.Select(r => r.RoleId); var socketGuildUser = Context.User as SocketGuildUser; if (!socketGuildUser.Roles.Any(sr => allowedRoleIds.Contains(sr.Id))) { await ReplyNoTagAsync("You don't have permission."); return; } //await ReplyAsync("Allowed"); if (argument.Length != 2) { await ReplyNoTagAsync("Invalid parameter count."); return; } var categoryName = argument[0]; var settingName = argument[1]; var mysteryPath = _mmrService.GetMysteryPath(Context.Guild.Id, categoryName, false); var settingPath = Path.Combine(mysteryPath, $"{FileUtils.MakeFilenameValid(settingName)}.json"); if (!File.Exists(settingPath)) { await ReplyNoTagAsync("Setting does not exist."); return; } File.Delete(settingPath); await ReplyNoTagAsync("Deleted mystery setting."); }