Skip to content

Instantly share code, notes, and snippets.

@KiroMusic
Created March 26, 2019 01:49
Show Gist options
  • Save KiroMusic/567e46b364a358c53545d497955df802 to your computer and use it in GitHub Desktop.
Save KiroMusic/567e46b364a358c53545d497955df802 to your computer and use it in GitHub Desktop.
[Command("mute")]
public async Task hasmuted(SocketGuildUser user, int time, string amount, [Remainder]string reason)
{
IReadOnlyCollection<SocketRole> Roles = Context.Guild.GetUser(Context.User.Id).Roles;
List<SocketRole> userroles = Roles.ToList();
var Staff = Context.Guild.Roles.FirstOrDefault(x => x.Name == $"{staffrole}");
if (userroles.Contains(Staff))
{
if (amount == "minute" || amount == "m" || amount == "minutes" || amount == "min" || amount == "mins")
{
time = (int)TimeSpan.FromMinutes(time).TotalMilliseconds;
}
if (amount == "second" || amount == "s" || amount == "seconds" || amount == "sec" || amount == "secs")
{
time = (int)TimeSpan.FromSeconds(time).TotalMilliseconds;
}
if (amount == "hour" || amount == "h" || amount == "hours" || amount == "hr" || amount == "hrs")
{
time = (int)TimeSpan.FromHours(time).TotalMilliseconds;
}
var useraccount = MuteAccounts.GetAccount(user.Id);
var accounts = UserAccounts.accounts;
var userAccount = UserAccounts.GetAccount(user.Id);
var punishment = new Punishment
{
ModID = Context.User.Id,
Reason = reason,
Type = "Mute"
};
var muted = new MuteAccount
{
ID = user.Id,
};
MuteAccounts.accounts.Add(muted);
MuteAccounts.SaveAccounts();
useraccount.MuteTimer.Interval = time;
useraccount.MuteTimer.Enabled = true;
userAccount.Punishments.Add(punishment);
UserAccounts.SaveAccounts();
GlobalTimer.Start();
await user.ModifyAsync(x => x.Mute = true);
var Muted = Context.Guild.Roles.FirstOrDefault(x => x.Name == $"{MutedRole}");
await user.AddRoleAsync(Muted);
await Context.Channel.SendMessageAsync($"{Context.Guild.Emotes.FirstOrDefault(x => x.Name == "check")} {user.Mention} has been muted for {time}{amount}");
}
else
{
await Context.Channel.SendMessageAsync($"{Context.Guild.Emotes.FirstOrDefault(x => x.Name == "xmark")}{Context.User.Mention} you have insignificant permissions.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment