public async Task AddModRole(IRole role) { var guild = ((SocketGuildChannel)Context.Channel).Guild; if (!await CheckPermission.CheckOwnerPermission( guild.OwnerId, Context.User.Id)) { await ReplyAsync("You are not the owner of this discord so cannot add credentials"); return; } var currentSettings = await _guildSettingsRepoistory.GetAsync(guild.Id); if (currentSettings == null) { currentSettings = new Bot.Core.GuildSettings { GuildId = guild.Id.ToString(), ModRoles = new List <string>() }; } currentSettings.ModRoles.Add(role.Id.ToString()); await _guildSettingsRepoistory.SaveAsync(currentSettings); await ReplyAsync("Role added as moderator"); }
public async Task ListOrgsAsync([Remainder] string orgName = "") { var guild = ((SocketGuildChannel)Context.Channel).Guild; var settings = await _guildSettingsRepoistory.GetAsync(guild.Id); if (!await CheckPermission.CheckOwnerPermission( guild.OwnerId, Context.User.Id )) { await ReplyAsync("You don't have permission to do this!"); return; } var current = await _ownerGitHubCredentialRepository.GetAsync(Context.User.Id); if (current == null) { await ReplyAsync("no github credentials set for you"); return; } if (string.IsNullOrEmpty(orgName)) { var allOrgs = await _gitHubService.GetGitHubOrgsAsync(current.AccessToken); if (allOrgs.Count() == 0) { await ReplyAsync("Alfred is not installed in any of your Organisations"); } var embed = new EmbedBuilder() .WithTitle("GitHub Organisations") .WithDescription("re-run `!github set-org` with the name of the organisation e.g. `!github set-org MyOrgName`") .AddField("Organisation Names", string.Join(" \r\n", allOrgs.Select(x => x.Login)), true) .Build(); await ReplyAsync(embed : embed); } else { var installs = await _gitHubService.GetGitHubInstallationsAsync(current.AccessToken); var install = installs.Installations .Where(x => x.TargetType == AccountType.Organization) .Where(x => x.Account.Login.ToLower() == orgName.ToLower()) .FirstOrDefault(); if (install == null) { await ReplyAsync("Alfred is not installed in any of your Organisations"); } settings.GitHubInstallationID = install.Id.ToString(); await _guildSettingsRepoistory.SaveAsync(settings); await ReplyAsync("Organisation set!"); } }