Skip to content

Instantly share code, notes, and snippets.

@KiroMusic
Created April 17, 2019 02:59
Show Gist options
  • Save KiroMusic/cacc2bb376d015fd28245b2a51299029 to your computer and use it in GitHub Desktop.
Save KiroMusic/cacc2bb376d015fd28245b2a51299029 to your computer and use it in GitHub Desktop.
[Command("time")]
public async Task starttime(int time)
{
var host = Context.Guild.GetRole(GuildAccounts.GetAccount(Context.Guild.Id).HostRole);
IReadOnlyCollection<SocketRole> Roles = Context.Guild.GetUser(Context.User.Id).Roles;
List<SocketRole> userroles = Roles.ToList();
if (userroles.Contains(host) || Context.Guild.GetUser(Context.User.Id).GuildPermissions.Has(GuildPermission.ManageMessages))
{
var guildAccount = GuildAccounts.GetAccount(Context.Guild.Id);
bool HalfTime = false;
bool DoubleTime = false;
Stopwatch Timer = new Stopwatch();
Timer.Start();
var embed = new EmbedBuilder();
embed.WithColor(new Color(97, 206, 122));
embed.WithDescription($"{Program.Client.GetGuild(563857280227999754).Emotes.FirstOrDefault(x => x.Name == "check")}{Context.User.Mention} I have set the timer to {time} seconds!!");
await Context.Channel.SendMessageAsync("", false, embed.Build());
while (Timer.IsRunning == true)
{
int Half = time / 2;
int doubled = Half / 2;
if (Timer.Elapsed.Seconds == Half && HalfTime == false)
{
HalfTime = true;
await Context.Channel.SendMessageAsync($"{Half} seconds left!!");
}
else if (Timer.Elapsed.Seconds == doubled * 3 && DoubleTime == false)
{
DoubleTime = true;
await Context.Channel.SendMessageAsync($"{Half / 2} seconds left!!");
}
else if (Timer.Elapsed.Seconds == time)
{
embed.WithColor(new Color(97, 206, 122));
embed.WithDescription("Time is up!!");
await Context.Channel.SendMessageAsync("", false, embed.Build());
Timer.Reset();
Timer.Stop();
HalfTime = false;
DoubleTime = false;
}
}
}
else
{
var embed = new EmbedBuilder();
embed.WithColor(new Color(247, 79, 79));
embed.WithDescription($"Missing; `Manage Messages` permission or `Host` role");
embed.WithTitle($"{Program.Client.GetGuild(563857280227999754).Emotes.FirstOrDefault(x => x.Name == "xmark")} You have insignificant permissions!");
await Context.Channel.SendMessageAsync("", false, embed.Build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment