static private ReadUser ( ulong id, string value ) : string | ||
id | ulong | |
value | string | |
return | string |
internal static int GetPermissions(User user, Channel channel) { if (user.Id == Program.masterId) { return(10); } return(SQL.ExecuteScalarPos($"select count(perms) from users where user = '******'") ? SQL.ReadInt(SQL.ReadUser(user.Id, "perms")) : 0); }
// Commands first to help with adding new commands static void GenerateCommands(CommandGroupBuilder group) { // User commands group.CreateCommand("servers") .Description("I'll send you statistics about the servers, channels and users (can be spammy, goes to private).") .MinPermissions(4) .Do(async e => { var output = ""; foreach (var server in client.Guilds) { output += $"{server.Name}: {server.TextChannels.Count()} text & {server.VoiceChannels.Count()} voice channels, {server.Users.Count()} users. ID: {server.Id}"; if (output.Length >= 2000) { var index = output.Length == 2000 ? 0 : output.LastIndexOf('\n'); await e.User.SendMessageAsync(Format.Code(index == 0 ? output : output.Substring(0, index))); output = index == 0 ? "" : output.Substring(index + 1); } else { output += '\n'; } } if (output.Any()) { await e.User.SendMessageAsync(Format.Code(output)); } }); group.CreateCommand("status") .Description("I'll tell you some useful stats about myself.") .Do(async e => await e.Channel.SendMessageAsync($"I'm connected to {client.Guilds.Count()} servers, which have a total of {client.Guilds.SelectMany(x => x.TextChannels).Count()} text and {client.Guilds.SelectMany(x => x.VoiceChannels).Count()} voice channels, and see a total of {client.Guilds.SelectMany(x => x.Users).Distinct().Count()} different users.\n{Format.Code($"Uptime: {Helpers.Uptime()}\n{Console.Title}")}")); group.CreateCommand("version") .Description("I'll tell you the current version and check if a newer version is available.") .Do(async e => await e.Channel.SendMessageAsync(VersionCheck())); Common.AddCommands(group); group.CreateCommand("playeravatar") .Parameter("username1", Commands.ParameterType.Required) .Parameter("username2", Commands.ParameterType.Optional) .Parameter("username3", Commands.ParameterType.Multiple) .Description("I'll get you the avatar of each Player.me username provided.") .Do(async e => { var rclient = Helpers.GetRestClient("https://player.me/api/v1/auth"); var request = new RestRequest("pre-login", Method.POST); foreach (string s in e.Args) { request.AddQueryParameter("login", s); JObject result = JObject.Parse(rclient.Execute(request).Content); await e.Channel.SendMessageAsync(s + (result["success"].ToObject <bool>() == false ? " was not found." : $"'s avatar: https:{result["results"]["avatar"]["original"]}")); } }); if (config["LastFM"].HasValues) { lfclient = new LastFM.LastfmClient(config["LastFM"]["apikey"].ToString(), config["LastFM"]["apisecret"].ToString()); group.CreateCommand("lastfm") .Parameter("username(s)", Commands.ParameterType.Unparsed) .Description("I'll tell you the last thing you, a lastfm user, or users on this server (if I know their lastfm) listened to.") .Do(async e => { var api = new LastFM.UserApi(lfclient.Auth, lfclient.HttpClient); var users = e.Args[0].Any() ? e.Message.MentionedUserIds.Any() ? e.Message.Tags.Where(x => x.Type == TagType.UserMention).Select(x => x.Value as IUser) : null : new[] { e.User }; var response = ""; if (users == null) { response = await GetLastScrobble(api, Tuple.Create(e.Args[0], e.Args[0], false)); } else { foreach (var user in (from u in users select Tuple.Create(SQL.ReadUser(u.Id, "lastfm"), u.Username, u == e.User))) { response += (user.Item1 != null ? await GetLastScrobble(api, user) : $"I don't know {(user.Item3 ? "your" : $"{user.Item2}'s")} lastfm yet{(user.Item3 ? ", please use the `setlastfm <username>` command" : "")}" ) + ".\n"; } }