public async Task StopProposalsAsync() { var photoBot = Service.PhotoBot; var winnerProposal = photoBot.Config.Proposals .OrderBy(element => Guid.NewGuid()) .ThenByDescending(element => element.Score) .First(); var proposalsChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentProposalsChannelId); var winnersChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.WinnerChannelId); using var client = new WebClient(); await client.DownloadFileTaskAsync(new Uri(winnerProposal.ImageUrl), "winner_proposal.png"); try { await winnersChannel.SendFileAsync("winner_proposal.png", $"Thema: {winnerProposal.Topic}"); } catch (Exception e) { Console.WriteLine(e); } var users = photoBot.Config.PhotoUserIds; photoBot.Config.UserIdToPhotoChannelId = new Dictionary <ulong, ulong>(); foreach (var userId in users) { var user = photoBot.SocketGuild.GetUser(userId); var photoChannel = await ChannelCreator.CreateChannelAsync($"photo-{user.Username}", photoBot.Config.PhotoCategoryId); var denyAllPermissions = new Overwrite(photoBot.Config.EveryoneRoleId, PermissionTarget.Role, OverwritePermissions.DenyAll(photoChannel)); var allowUserPermissions = new Overwrite(userId, PermissionTarget.User, OverwritePermissions.AllowAll(photoChannel)); var permissions = new List <Overwrite> { denyAllPermissions, allowUserPermissions }; await photoChannel.ModifyAsync(prop => prop.PermissionOverwrites = permissions); photoBot.Config.UserIdToPhotoChannelId.Add(userId, photoChannel.Id); } await Archiver.ArchiveChannelAsync(proposalsChannel); await PhotoConfig.SaveAsync(); }
public async Task StartBattleAsync() { var photoBot = Service.PhotoBot; await ReplyAsync("Starting new photoshop battle."); var proposalsChannel = await ChannelCreator.CreateChannelAsync("proposals", photoBot.Config.PhotoCategoryId); if (photoBot.Config.CurrentProposalsChannelId != 0) { var oldProposalsChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentProposalsChannelId); await Archiver.ArchiveChannelAsync(oldProposalsChannel); } if (photoBot.Config.CurrentVotingChannelId != 0) { var oldVotingChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentVotingChannelId); await Archiver.ArchiveChannelAsync(oldVotingChannel); } if (photoBot.Config.UserIdToPhotoChannelId != null) { foreach (var(_, value) in photoBot.Config.UserIdToPhotoChannelId) { if (value == 0) { continue; } var channel = photoBot.SocketGuild.GetTextChannel(value); if (channel != null) { await channel.DeleteAsync(); } } } photoBot.Config.CurrentProposalsChannelId = proposalsChannel.Id; await photoBot.GetPhotoUsersAsync(); photoBot.Config.Proposals = new List <PhotoMessage>(); photoBot.Config.Photos = new List <PhotoMessage>(); photoBot.Config.UserIdToPhotoChannelId = new Dictionary <ulong, ulong>(); await PhotoConfig.SaveAsync(); }
public async Task StopVotingAsync() { var photoBot = Service.PhotoBot; var winner = photoBot.Config.Photos .OrderBy(element => Guid.NewGuid()) .ThenByDescending(element => element.Score) .First(); var winnerChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.WinnerChannelId); var winnerUser = photoBot.SocketGuild.GetUser(winner.UserId); using var webClient = new WebClient(); await webClient.DownloadFileTaskAsync(winner.ImageUrl, "winner.png"); await winnerChannel.SendFileAsync("winner.png", $"The winner is: {winnerUser.Username}"); var votingChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentVotingChannelId); await Archiver.ArchiveChannelAsync(votingChannel); }