public async Task Roll(int sides = 6) { int die1 = Controller.Instance.rand.Next(1, sides); int die2 = Controller.Instance.rand.Next(1, sides); await ReplyAsync($"{Context.User.Username} rolled a {die1} and a {die2}."); if (die1 == die2 && !(Context.Channel is IDMChannel)) { BotUsers.IgnoredUsers.Add(Context.User.Id); await ReplyAsync($"Hey {Context.User.Mention} you will be muted for 30 seconds, " + $"and your commands ignored."); IGuildUser guser = Context.Message.Author as IGuildUser; if (guser.VoiceChannel == null) { if (Controller.Instance.servers.TryGetValue(guser.GuildId, out Dictionary <string, List <ulong> > serverMembers)) { serverMembers["mute"].Add(guser.Id); } } else { await guser.ModifyAsync(properties => properties.Mute = true); } MyScheduler.RunOnce(DateTime.Now.AddSeconds(30), async() => { if (guser.VoiceChannel == null) { // If they haven't been muted yet, remove them from the 'to mute' list and don't add to 'to unmute' list if (Controller.Instance.servers.TryGetValue(guser.GuildId, out Dictionary <string, List <ulong> > serverMembers)) { // If the user wasn't removed from the list then they were already muted, so add to unmute list if (!serverMembers["mute"].Remove(guser.Id)) { serverMembers["unmute"].Add(guser.Id); } } } else { await guser.ModifyAsync(properties => properties.Mute = false); } BotUsers.IgnoredUsers.Remove(Context.User.Id); await ReplyAsync($"Hey {Context.User.Mention}, you are now unmuted and I will listen to your commands."); }); } }
public async Task Remind(string time, [Remainder] string reminder = "nothing") { if (string.IsNullOrEmpty(time)) // Exit if there wasn't an argument { return; } int seconds = 0; char modifier = time.FirstOrDefault(character => char.IsLetter(character)); if (!int.TryParse(string.Join("", time.Where(character => char.IsDigit(character))), out seconds)) { seconds = 3600; modifier = 's'; } switch (modifier) { case 'w': // week seconds *= 604800; break; case 'd': // day seconds *= 86400; break; case 'h': // hour seconds *= 3600; break; case 'm': // minute seconds *= 60; break; case 's': case default(char): break; default: seconds = 10; break; // seconds and default keep seconds as seconds } if (seconds <= 0) // If seconds are negative, set default to one hour { seconds = 60; } int minutes = 0; int hours = 0; int days = 0; if (seconds >= 60) { minutes = seconds / 60; seconds %= 60; } if (minutes >= 60) { hours = minutes / 60; minutes %= 60; } if (hours >= 24) { days = hours / 24; hours %= 24; } string message = $"Hey! Listen! {Context.Message.Author.Mention}. " + $"You asked me to remind you about \"{reminder}\", here's your reminder!"; DateTime remindTime = DateTime.Now.AddDays(days). AddHours(hours).AddMinutes(minutes).AddSeconds(seconds); MyScheduler.RunOnce(remindTime, async() => { await ReplyAsync(message); }); await ReplyAsync($"Okay, I will remind you about \"{reminder}\" " + $"in {days} days, {hours} hours, {minutes} minutes, and {seconds} seconds."); }