Skip to content

Instantly share code, notes, and snippets.

@KiroMusic
Created April 17, 2019 01:59
Show Gist options
  • Save KiroMusic/9f8e3b8c817633bab612ed2c075bab45 to your computer and use it in GitHub Desktop.
Save KiroMusic/9f8e3b8c817633bab612ed2c075bab45 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);
guildAccount.HalfTime = false;
guildAccount.DoubleTime = false;
guildAccount.Timer.Reset();
guildAccount.Timer.Start();
guildAccount.Time = time;
GuildAccounts.SaveAccounts();
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 (guildAccount.Timer.IsRunning == true)
{
int Half = time / 2;
int doubled = Half / 2;
if (guildAccount.Timer.Elapsed.Seconds == Half && guildAccount.HalfTime == false)
{
guildAccount.HalfTime = true;
GuildAccounts.SaveAccounts();
await Context.Channel.SendMessageAsync($"{Half} seconds left!!");
}
else if (guildAccount.Timer.Elapsed.TotalSeconds == doubled * 3 && guildAccount.DoubleTime == false)
{
guildAccount.DoubleTime = true;
GuildAccounts.SaveAccounts();
await Context.Channel.SendMessageAsync($"{Half / 2} seconds left!!");
}
else if (guildAccount.Timer.Elapsed.Seconds == time)
{
embed.WithColor(new Color(97, 206, 122));
embed.WithDescription("Time is up!!");
await Context.Channel.SendMessageAsync("", false, embed.Build());
guildAccount.Timer.Reset();
guildAccount.Timer.Stop();
guildAccount.HalfTime = false;
guildAccount.DoubleTime = false;
GuildAccounts.SaveAccounts();
}
}
}
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