public async Task SetAlarm(CommandContext ctx, string alarmname, [RemainingText, Description("Alarm time ex 4:20 or 15:34")] string datestring) { // get member's voice state var vstat = ctx.Member?.VoiceState; if (vstat?.Channel == null) { // they did not specify a channel and are not in one await ctx.RespondAsync("You are not in a voice channel."); return; } string[] datestringComps = datestring.Split(':'); if (datestringComps.Length == 2) { int parsedHours, parsedMinutes; if (int.TryParse(datestringComps[0], out parsedHours) && int.TryParse(datestringComps[1], out parsedMinutes)) { if (parsedHours > 0 && parsedHours < 24 && parsedMinutes > 0 && parsedMinutes < 60) { int hourdiff = (parsedHours - DateTime.Now.Hour) % 24; if (hourdiff < 0) { hourdiff += 24; } int mindiff = (parsedMinutes - DateTime.Now.Minute) % 60; DateTime dt = DateTime.Now.AddHours(hourdiff).AddMinutes(mindiff).AddSeconds(-DateTime.Now.Second); GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, vstat.Channel.Guild, true); handler.AddAlarm(dt, alarmname, ctx.User.Id); if (!handler.IsRunning) //If the handler isn't running for some reason start it TODO: remove these, or implement handler sleep { handler.Execute(); //Will run async } } } } await ctx.RespondAsync($"Registered alarm `{alarmname}` to `{ctx.User.Username}`"); }
public async Task CancelAlarm(CommandContext ctx, string alarmname) { GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Guild); List <AlarmData> alarms = handler.GetAlarms(); for (int i = 0; i < alarms.Count; i++) { if (alarms[i].AlarmName == alarmname && alarms[i].userId == ctx.User.Id) { alarms.RemoveAt(i); handler.SaveGuildData(); await ctx.RespondAsync($"Canceled alarm `{alarmname}`"); return; } } await ctx.RespondAsync($"Couldn't find alarm `{alarmname}`"); }
public async Task ListAlarm(CommandContext ctx, DiscordChannel channel = null) { GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Channel.Guild, false); if (handler != null) { List <AlarmData> alarms = handler.GetAlarms(); string[] alarmtexts = new string[alarms.Count]; for (int i = 0; i < alarmtexts.Length; i++) { DiscordMember member = await ctx.Guild.GetMemberAsync(alarms[i].userId); alarmtexts[i] = $"{member.Username}: {alarms[i].AlarmDate.ToShortTimeString()} ({alarms[i].AlarmName})"; } string alarmstext = String.Join("`\n`", alarmtexts); await ctx.RespondAsync($"Currently Alarms:\n{alarmstext}"); return; } await ctx.RespondAsync($"Currently not registered to any channel, use `!kk register` while in a voice channel to add it."); }