public async Task Create(string eventName, string shortName, int?capacity = null) { var author = Context.Message.Author as SocketGuildUser; if (!await _permissionService.UserIsModeratorAsync(Context, author)) { await Context.Channel.SendMessageAsync("You dont have permission to create events"); return; } var existingEvent = await _events.GetActiveEvent(eventName, Context.Guild.Id); var existingEventWithAlias = await _events.GetActiveEvent(shortName, Context.Guild.Id); if (existingEvent != null || existingEventWithAlias != null) { await Context.Channel.SendMessageAsync("There is already an active event with that name or short name. Event names must be unique!"); return; } string roleId = ""; try { /* Create a new role for this event. The role is not visible in the sidebar and can be menitoned. * It is possible that the shortName is already used for a role, but that's not forbidden by Discord. * It might be a consideration for the future to check for duplicates and assign a unique name. */ var role = await author.Guild.CreateRoleAsync(shortName + " notify", null, null, false, true); roleId = role.Id.ToString(); } catch (Discord.Net.HttpException) { /* ignore forbidden exception */ } var @event = new Models.Event { ChannelId = Context.Channel.Id.ToString(), GuildId = Context.Guild.Id.ToString(), RoleId = roleId, ShortName = shortName, Closed = false, Name = eventName, Capacity = capacity }; await _events.SaveAsync(@event); existingEvent = await _events.GetActiveEvent(eventName, Context.Guild.Id); await Context.Channel.SendMessageAsync($"{Context.Message.Author.Mention} has created the event {eventName}! React to the message below to sign up to the event. If you can no longer attend, simply remove your reaction!"); await _eventParticipantService.CreateAndPinParticipantMessage(Context.Channel, existingEvent); }
public async Task Standings() { var sb = new StringBuilder(); List <string> listOfUnknownChampionships = new List <string>(); List <string> listOfSuccessfulyUploadedChampionships = new List <string>(); try { var author = Context.Message.Author as SocketGuildUser; if (!await _permissionService.UserIsModeratorAsync(Context, author)) { await Context.Channel.SendMessageAsync("You dont have permission to create events"); return; } var guildId = Context.Guild.Id; // clear out our results DB table first await _results.DeleteAllGuildEvents <ChampionshipResultsModel>(guildId.ToString()); var attachment = Context.Message.Attachments.First(); var excelDriverDataModels = await _excelService.ReadResultsDataFromAttachment(attachment); List <ChampionshipResultsModel> championshipResults = new List <ChampionshipResultsModel>(); foreach (ExcelDriverDataModel excelDriverDataModel in excelDriverDataModels) { var e = await _events.GetActiveEvent(excelDriverDataModel.Championship, guildId); if (e == null || e.Id == 0) { if (!listOfUnknownChampionships.Contains(excelDriverDataModel.Championship)) { listOfUnknownChampionships.Add(excelDriverDataModel.Championship); } continue; } else { if (!listOfSuccessfulyUploadedChampionships.Contains(excelDriverDataModel.Championship)) { listOfSuccessfulyUploadedChampionships.Add(excelDriverDataModel.Championship); } } var eventId = e.Id; ChampionshipResultsModel championshipResult = new ChampionshipResultsModel() { EventId = eventId, Pos = excelDriverDataModel.Pos, Driver = excelDriverDataModel.Driver, Number = excelDriverDataModel.Number, Car = excelDriverDataModel.Car, Points = excelDriverDataModel.Points, Diff = excelDriverDataModel.Diff }; championshipResults.Add(championshipResult); } await _results.AddAsync(championshipResults); } catch (Exception ex) { sb.AppendLine($"Error when doing import: {ex.Message}"); } if (listOfSuccessfulyUploadedChampionships.Count > 0) { sb.AppendLine($"Data has been imported for the following championships: {string.Join(", ", listOfSuccessfulyUploadedChampionships)}"); } if (listOfUnknownChampionships.Count > 0) { sb.AppendLine($"The following championship shortnames were not found in events: {string.Join(", ", listOfUnknownChampionships)}"); } await ReplyAsync(sb.ToString()); }