public async Task Warn(SocketUser user, [Remainder] string reason = "Unspecified Reason") { if (await MiXLib.GetRank(user.Id, Context.Guild) > 0) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** User is a staff member, cannot warn.", color: new Color(200, 0, 0))); return; } var w = new Warn(user.Id, Context.User.Id, reason, MiXLib.tick(), MiXLib.tick() + 18000); await Core.Guilds[Context.Guild.Id].AddWarnAsync(w); await ReplyAsync("", false, MiXLib.GetEmbed("Successfully warned user.", color: new Color(255, 140, 0))); }
public async override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) { var Context = context as SocketCommandContext; SocketGuildUser usr = Context.Guild.GetUser(context.User.Id); if (Guild != 0 && context.Guild.Id != Guild) { return(PreconditionResult.FromError("Unknown command.")); } else if (await MiXLib.GetRank(usr.Id, Context.Guild) < Rank) { return(PreconditionResult.FromError("You do not have permission to run this command!")); } return(PreconditionResult.FromSuccess()); }
public async Task HelpCommand([Remainder] string command = null) { var AvailableCommands = new List <Command>(); foreach (Command c in Core.Commands) { if (c.Listed == false) { continue; } else if (c.Rank > await MiXLib.GetRank(Context.User.Id, Context.Guild)) { continue; } else if (c.Guild != 0 && c.Guild != Context.Guild.Id) { continue; } AvailableCommands.Add(c); } if (command == null) { await ReplyAsync("", false, MiXLib.GetEmbed( $"Rank: **{MiXLib.GetRankName(await MiXLib.GetRank(Context.User.Id, Context.Guild))}**\n" + $"Available Commands (**{AvailableCommands.Count.ToString()}**): {(new Func<string>(() => { var cmds = new List<string>(); foreach (Command c in AvailableCommands) cmds.Add(c.Name); return MiXLib.Concat(cmds, ", ", "**", "**"); }))()}\n\n" + $"Run **{Core.Guilds[Context.Guild.Id].Config.Prefix}help <command>** for more info")); } else { var Command = Core.GetCommand(command); if (Command == null || Command.Listed == false || (Command.Guild != 0 && Command.Guild != Context.Guild.Id)) { await ReplyAsync("", false, MiXLib.GetEmbed($"**Error**: Could not find command **{command}**.", null, new Color(200, 0, 0))); return; } await ReplyAsync("", false, MiXLib.GetEmbed( $"Command Name: **{Command.Name}**\n" + $"Description: **{Command.Description}**\n" + $"Aliases: {MiXLib.Concat(Command.Aliases, ", ", "**", "**")}\n" + $"Usage: **{Command.Usage}**\n" + $"Minimum Rank: **{MiXLib.GetRankName(Command.Rank)}**\n" + $"User can run: **{MiXLib.BoolToYesNo(await MiXLib.GetRank(Context.User.Id, Context.Guild) >= Command.Rank)}**" )); } }
public async Task SetRank(SocketUser user, [Remainder] string rankstr) { var rank = MiXLib.Rank.User; try { rank = (MiXLib.Rank)Convert.ToInt32(rankstr); } catch (Exception ex) { rankstr = rankstr.ToLower(); if (rankstr.Contains("owner")) { rank = MiXLib.Rank.GuildOwner; } else if (rankstr.Contains("admin")) { rank = MiXLib.Rank.Administrator; } else if ((rankstr.Contains("sr") || rankstr.Contains("senior")) && rankstr.Contains("mod")) { rank = MiXLib.Rank.SeniorModerator; } else if (!(rankstr.Contains("sr") || rankstr.Contains("senior")) && !(rankstr.Contains("jr") || rankstr.Contains("junior")) && rankstr.Contains("mod")) { rank = MiXLib.Rank.Moderator; } else if ((rankstr.Contains("jr") || rankstr.Contains("junior")) && rankstr.Contains("mod")) { rank = MiXLib.Rank.JuniorModerator; } else { rank = MiXLib.Rank.User; } }; if (rank > await MiXLib.GetRank(Context.User.Id, Context.Guild)) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** You cannot set peoples ranks to a rank higher than your own.", null, new Color(200, 0, 0))); return; } Core.Guilds[Context.Guild.Id].Users[user.Id] = (int)rank; await ReplyAsync("", false, MiXLib.GetEmbed($"Successfully set {user.Mention}'s rank to **{MiXLib.GetRankName(rank)}**!")); }
public async Task Kick(SocketUser user, [Remainder] string reason = "Unspecified Reason") { if (await MiXLib.GetRank(user.Id, Context.Guild) >= await MiXLib.GetRank(Context.User.Id, Context.Guild)) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** You do not outrank this user.", color: new Color(200, 0, 0))); return; } else if (Context.Guild.GetUser(user.Id).Hierarchy > Context.Guild.GetUser(Context.Client.CurrentUser.Id).Hierarchy || Context.Guild.OwnerId == user.Id) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** User outranks bot, no permissions.", color: new Color(200, 0, 0))); return; } await Core.Guilds[Context.Guild.Id].KickUserAsync(user.Id, Context.User.Id, reason); await ReplyAsync("", false, MiXLib.GetEmbed("Successfully kicked user.", color: new Color(0, 0, 0))); }
public async Task Play([Remainder] string video) { var New = false; var Guild = Core.Guilds[Context.Guild.Id]; var User = Context.Guild.GetUser(Context.User.Id); if (User.VoiceChannel == null && !(Core.AudioSessions.ContainsKey(Guild) && await MiXLib.GetRank(User.Id, Context.Guild) > MiXLib.Rank.User)) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** User is not in a voice channel.", null, new Color(200, 0, 0))); return; } AudioSession AudioSession = null; if (!Core.AudioSessions.ContainsKey(Guild)) { var client = await User.VoiceChannel.ConnectAsync(); AudioSession = new AudioSession(client, Guild); Core.AudioSessions[Guild] = AudioSession; New = true; } else if (User.VoiceChannel != Context.Guild.GetUser(Context.Client.CurrentUser.Id).VoiceChannel&& await MiXLib.GetRank(User.Id, Context.Guild) < MiXLib.Rank.JuniorModerator) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** User is in different voice channel.", null, new Color(200, 0, 0))); return; } else { AudioSession = Core.AudioSessions[Guild]; } MiXLib.VideoType type = MiXLib.VideoType.nil; if ( ( video.StartsWith("https://www.youtube.com/watch?v=") || video.StartsWith("http://www.youtube.com/watch?v=") || video.StartsWith("https://youtube.com/watch?v=") || video.StartsWith("http://youtube.com/watch?v=") /*|| * video.StartsWith("https://youtu.be/") || * video.StartsWith("http://youtu.be/") */ ) && !video.Contains(' ') && !video.Contains('\n') ) { type = MiXLib.VideoType.URL; } else { type = MiXLib.VideoType.Search; } var id = ""; if (type == MiXLib.VideoType.Search) { id = await Song.IDFromSearchAsync(video); } else { id = video.Substring(video.IndexOf("?v=") + 3); } if (AudioSession.Queue.ContainsKey(id)) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** Cannot add song that is already queued into the queue.", null, new Color(200, 0, 0))); return; } Song song; if (type == MiXLib.VideoType.URL) { song = await Song.FromURLAsync(video); } else { song = await Song.FromSearchAsync(video); } AudioSession.Queue.Add(song.ID, song); if (New) { while (AudioSession.Queue.Count > 0) { AudioSession.Client.Disconnected += async(ex) => { await Task.Delay(0); AudioSession.Queue.Clear(); Core.AudioSessions.Remove(Guild); if (ex == null) { await ReplyAsync("", false, MiXLib.GetEmbed("Queue Concluded.")); } }; var Song = AudioSession.Queue.FirstOrDefault().Value; await ReplyAsync("", false, MiXLib.GetEmbed($"Playing **{Song.Name}**")); await MiXLib.SendAudioAsync(AudioSession.Client, Song.FilePath); await Task.Delay(Song.Duration); Song.Dispose(); AudioSession.Queue.Remove(Song.ID); await Task.Delay(1000); } } await AudioSession.EndAsync(); await ReplyAsync("", false, MiXLib.GetEmbed("Queue Concluded.")); }
public async Task Ban(SocketUser user, string duration = "-1", [Remainder] string reason = "Unspecified Reason") { if (await MiXLib.GetRank(user.Id, Context.Guild) >= await MiXLib.GetRank(Context.User.Id, Context.Guild)) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** You do not outrank this user.", color: new Color(200, 0, 0))); return; } else if (Context.Guild.GetUser(user.Id).Hierarchy > Context.Guild.GetUser(Context.Client.CurrentUser.Id).Hierarchy || Context.Guild.OwnerId == user.Id) { await ReplyAsync("", false, MiXLib.GetEmbed("**Error:** User outranks bot, no permissions.", color: new Color(200, 0, 0))); return; } var IsPermanent = false; var EndTime = MiXLib.tick(); if (duration == null) { EndTime += 604800; } else if (duration == "inf" || duration == "perm" || duration == "permanent" || duration == "forever" || duration == "0" || duration == "-1") { IsPermanent = true; EndTime = -1; } else { double length = 0; try { length = Convert.ToDouble(duration.Substring(0, duration.Length - 1)); } catch (Exception ex) { length = Convert.ToDouble(duration); } var suf = ""; try { suf = duration.Substring(duration.Length - 1); } catch (Exception ex) { suf = "m"; } try { Convert.ToDouble(suf); length = Convert.ToDouble(duration); suf = "m"; } catch (Exception ex) { } if (suf == "y") { length = (((length * 60) * 60) * 24) * 365; } else if (suf == "d") { length = ((length * 60) * 60) * 24; } else if (suf == "h") { length = (length * 60) * 60; } else if (suf == "m") { length = length * 60; } else if (suf == "s") { length = length; } if (length <= 0) { IsPermanent = true; EndTime = -1; } else { EndTime += length; } } /*var LengthString = MiXLib.FormatTime(Convert.ToInt32(EndTime - MiXLib.tick())); * if (IsPermanent) * { * LengthString = "forever"; * }*/ var b = new Ban(user.Id, Context.User.Id, reason, MiXLib.tick(), EndTime, IsPermanent); await Core.Guilds[Context.Guild.Id].AddBanAsync(b); await ReplyAsync("", false, MiXLib.GetEmbed("Successfully banned user.", color: new Color(1, 1, 1))); }