public async Task <PugEvent> GetEvent(DiscordMessage msg) { PugEvent eve = new PugEvent(); using (SqlConnection conn = new SqlConnection(connStr)) using (SqlCommand cmd = new SqlCommand($"SELECT TOP 1 * FROM dbo.Events WHERE Discord_Message_ID = '{msg.Id}'", conn)) // rpl w sp { await conn.OpenAsync(); var reader = await cmd.ExecuteReaderAsync(); if (!reader.Read()) { throw new InvalidOperationException("No event records were returned."); } eve.ID = reader.GetGuid(reader.GetOrdinal("ID")); eve.Scheduled_Date = reader.GetDateTime(reader.GetOrdinal("Scheduled_Date")); eve.Created_On = reader.GetDateTime(reader.GetOrdinal("Created_On")); eve.Discord_Message_ID = reader.GetString(reader.GetOrdinal("Discord_Message_ID")); if (reader.Read()) { throw new InvalidOperationException("Multiple event records were returned."); } return(await Task.FromResult(eve)); } }
public async Task <List <PugEvent> > GetCurrentEvents() { using (SqlConnection conn = new SqlConnection(connStr)) using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.Events WHERE Scheduled_Date >= GETDATE()", conn)) // rpl w sp { await conn.OpenAsync().ConfigureAwait(false); try { using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { PugEvent e = new PugEvent(); e.ID = reader.GetGuid(reader.GetOrdinal("ID")); e.Scheduled_Date = reader.GetDateTime(reader.GetOrdinal("Scheduled_Date")); e.Created_On = reader.GetDateTime(reader.GetOrdinal("Created_On")); e.Discord_Message_ID = reader.GetString(reader.GetOrdinal("Discord_Message_ID")); Events.Add(e); } } return(await Task.FromResult(Events)); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(await Task.FromResult(Events)); } } }
public async Task AnnounceEvent(CommandContext ctx, DateTime scheduledDate, DiscordMessage msg) { DiscordChannel channel = await ctx.Client.GetChannelAsync(UInt64.Parse(pugAnnouncementsChannel_ID)); DiscordMessage message = await channel.SendMessageAsync($"New Pug Event scheduled on {scheduledDate.ToShortDateString()} at {scheduledDate.ToShortTimeString()}! Please react to sign-up! (Any reaction)"); try { await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":YEA:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":NAY:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":DamageLogo:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":TankLogo:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":SupportLogo:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":ZzZz:")); } catch (Exception ex) { Console.WriteLine(ex.Message); } PugEvent e = new PugEvent(); e.Scheduled_Date = scheduledDate; e.Discord_Message_ID = message.Id.ToString(); Data.eventsTableAdapter.InsertQuery(scheduledDate, message.Id.ToString()); await msg.ModifyAsync("The event has been scheduled!").ConfigureAwait(false); }
public async Task AnnounceEvent(CommandContext ctx, DateTime scheduledDate, DiscordMessage msg) { DiscordChannel channel = await ctx.Client.GetChannelAsync(UInt64.Parse(pugAnnouncementsChannel_ID)); DiscordMessage message = await channel.SendMessageAsync($"New Pug Event scheduled on {scheduledDate.ToShortDateString()} at {scheduledDate.ToShortTimeString()}!"); PugEvent e = new PugEvent(); e.Scheduled_Date = scheduledDate; e.Discord_Message_ID = message.Id.ToString(); await db.CreateEvent(e); await msg.ModifyAsync("The event has been scheduled!").ConfigureAwait(false); }
public async Task CreateEvent(PugEvent e) { using (SqlConnection conn = new SqlConnection(connStr)) using (SqlCommand cmd = new SqlCommand($"INSERT INTO dbo.Events (Scheduled_Date, Discord_Message_ID) VALUES ('{e.Scheduled_Date}','{e.Discord_Message_ID}')", conn)) // rpl w sp { await conn.OpenAsync().ConfigureAwait(false); try { Console.WriteLine(cmd.CommandText); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } await Task.CompletedTask; }
public async Task CreateRegistration(Player player, PugEvent e) { await Query($"DELETE FROM dbo.Registrations WHERE Event_ID = '{e.ID}' AND Player_ID = '{player.ID}'"); using (SqlConnection conn = new SqlConnection(connStr)) using (SqlCommand cmd = new SqlCommand($"INSERT INTO dbo.Registrations (Event_ID, Player_ID, Player_Cancelled) VALUES ('{e.ID}','{player.ID}', null)", conn)) // rpl w sp { await conn.OpenAsync().ConfigureAwait(false); try { Console.WriteLine(cmd.CommandText); await cmd.ExecuteNonQueryAsync(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } await Task.CompletedTask; }
public async Task UpdateRegistration(Player player, PugEvent e) { await Query($"UPDATE dbo.Registrations SET Player_Cancelled = '1' WHERE Event_ID = '{e.ID}' AND Player_ID = '{player.ID}'"); await Task.CompletedTask; }