public async Task SetMemberLevel(CommandContext ctx, [RemainingText] string text) { int requesterLevel = UserLevels.GetLevel(ctx.User.Id, ctx.Guild.Id); var textArray = text.Split(" "); int level; if (!int.TryParse(textArray[0], out level)) { await CTX.RespondSanitizedAsync(ctx, $"{textArray[0]} is not a valid level."); return; } if (level >= requesterLevel) { await CTX.RespondSanitizedAsync(ctx, "You cannot assign a level higher than your own"); return; } Dictionary <ulong, bool> idList = PrepareUserIdList(ctx.Message.MentionedUsers, textArray); ctx.Message.MentionedRoles.ToList().ForEach(role => { if (!idList.ContainsKey(role.Id)) { idList.Add(role.Id, true); } }); await SetLevelsFromList(ctx, idList, level, requesterLevel); }
private async Task SetLevelsFromList(CommandContext ctx, Dictionary <ulong, bool> idList, int level, int requesterLevel) { List <ulong> failedIDs = new List <ulong>(); bool isGlobal = requesterLevel == (int)ShimaConsts.UserPermissionLevel.SHIMA_TEAM; foreach (var item in idList) { if (isGlobal || UserLevels.GetLevel(item.Key, ctx.Guild.Id) < requesterLevel) { if (!await UserLevels.SetLevel(item.Key, ctx.Guild.Id, item.Value, level)) { failedIDs.Add(item.Key); } } } string response = $"Successfully assigned level to {idList.Count() - failedIDs.Count()} IDs"; if (failedIDs.Count() > 0) { response += $"\nFailed to assign level to: {string.Join(", ", failedIDs)}"; } await CTX.RespondSanitizedAsync(ctx, response); }
public async Task DisplayUserInfo(CommandContext ctx, [RemainingText] string commandPayload) { var members = new List <DiscordMember>(); var uidList = Utils.GetIdListFromMessage(ctx.Message.MentionedUsers, commandPayload); foreach (var id in uidList) { if (ctx.Guild.Members.ContainsKey(id)) { members.Add(ctx.Guild.Members[id]); } else { await CTX.RespondSanitizedAsync(ctx, $"Unable to find user with ID {id} on the server"); return; } } if (members.Count == 0) { members.Add(ctx.Member); } foreach (var member in members) { var userLevel = UserLevels.GetLevel(member.Id, ctx.Guild.Id); var globalUserLevel = UserLevels.GetMemberLevel(member); var roles = string.Join(", ", from role in member.Roles select role.Mention); var customStatus = string.Concat( member.Presence.Activity.CustomStatus?.Emoji ?? "", member.Presence.Activity.CustomStatus?.Name ?? ""); if (string.IsNullOrEmpty(customStatus)) { customStatus = null; } // Header var userInfo = new DiscordEmbedBuilder() .WithAuthor($"{member.Username}#{member.Discriminator} ({member.Id})", "", member.AvatarUrl) .WithTimestamp(DateTime.Now) .WithColor(new DiscordColor("#3498db")) .WithThumbnail(member.AvatarUrl) .WithUrl(member.AvatarUrl) .AddField($"Status", $"```\n{member.Presence.Status}```", true); // Activities string streams = null; string games = null; foreach (var act in member.Presence.Activities) { if (act.ActivityType is ActivityType.Custom) { continue; } // So basically, am very tiny. In case you really need to know i just need a matching type lol. // It's discarded anyway and a .ToString() still executes. // Should a C style switch not have this problem it could be more elegant, if verbose af. _ = act.ActivityType switch { ActivityType.Watching => userInfo .AddField($"Watching", $"```{act.Name}```").ToString(), ActivityType.ListeningTo => userInfo .AddField($"Listening to", $"```{act.Name}```").ToString(), ActivityType.Playing => games += $"```{act.Name}```", ActivityType.Streaming => streams += $"```{act.RichPresence.Details}```\n{act.StreamUrl}", _ => throw new NotImplementedException() }; } if (games?.Length > 0) { userInfo.AddField($"Playing", $"{games} "); } if (streams?.Length > 0) { userInfo.AddField($"Streaming", $"{streams} "); } // Account info userInfo .AddField($"Custom status", $"\n{customStatus ?? "No custom status set"}") .AddField($"Account Creation", $"```\n{member.CreationTimestamp.UtcDateTime} UTC```", false) .AddField($"Joined on", $"```\n{member.JoinedAt.UtcDateTime} UTC```") .AddField($"Server access level", $@"```{ userLevel switch { (int) ShimaConsts.UserPermissionLevel.DEFAULT => $"Default ({(int) ShimaConsts.UserPermissionLevel.DEFAULT})", (int) ShimaConsts.UserPermissionLevel.DEFAULT_SERVER_OWNER => $"Server owner ({(int) ShimaConsts.UserPermissionLevel.DEFAULT_SERVER_OWNER})", (int) ShimaConsts.UserPermissionLevel.SHIMA_TEAM => "Bot owner", _ => userLevel.ToString() }