public async Task RegisterMsg( [Summary("ID of message you want to use a description for what theese roles do.")]ulong msgId, [Summary("ID or names for the roles you want selectable.")]params string[] roles) { IUserMessage msg = (IUserMessage)await Channel.GetMessageAsync(msgId); List<IRole> guildRoles = await GetRoles(roles); List<IEmote> emotes = msg.Reactions.Select(x => x.Key).ToList(); if (roles.Length > emotes.Count) { await RespondAsync("Too many input roles, each reaction must have one role.", false, false); return; } if (roles.Length < emotes.Count) { await RespondAsync("Not enough input roles, each reaction must have one role.", false, false); return; } // Go through all reactions on target message and add the bots own reaction and sync DB for (int i = 0; i < emotes.Count; i++) { IEmote emote = emotes[i]; IRole role = guildRoles[i]; await DatabaseModule.RunNonQueryAsync(Config.RoleDatabase, $"INSERT INTO reactionMessages VALUES ({msg.Id}, '{emote.Name.GetHashCode()}', {role.Id});"); await msg.AddReactionAsync(emote); } // Delete traces of this command being talked about. await Message.DeleteAsync(); }
/// <summary> /// Change a role status for a user. (Will ignore any roles that are not manages) /// </summary> /// <param name="user"></param> /// <param name="action"></param> /// <param name="roles"></param> /// <returns></returns> public async Task ModifyRoleAsync(IGuildUser user, RoleAction action, params string[] roles) { // TODO: Fix manual add settings. foreach (IRole role in await GetRoles(roles)) { // Skip roles that are not managed. if (!Config.RolesToManage.Any(x => x.RoleID == role.Id)) { await LogAsync(LogLevel.Warning, "Trying to modify role that has not been configured to be manages."); continue; } // Take appropriate action based on input. switch (action) { case RoleAction.Add: await DatabaseModule.RunNonQueryAsync(Config.RoleDatabase, $"INSERT INTO userRoles VALUES ({user.Id}, {role.Id});"); break; case RoleAction.Remove: await DatabaseModule.RunNonQueryAsync(Config.RoleDatabase, $"DELETE FROM userRoles where user_id = {user.Id} AND role_id = {role.Id}"); break; case RoleAction.AddManual: ManagedRole managedRole = Config.RolesToManage.First(x => x.RoleID == role.Id); if (managedRole.ManualAdd) await DatabaseModule.RunNonQueryAsync(Config.RoleDatabase, $"INSERT INTO userRoles VALUES ({user.Id}, {role.Id});"); break; case RoleAction.RemoveManual: managedRole = Config.RolesToManage.First(x => x.RoleID == role.Id); if (managedRole.ManualAdd) await DatabaseModule.RunNonQueryAsync(Config.RoleDatabase, $"DELETE FROM userRoles where user_id = {user.Id} AND role_id = {role.Id}"); break; default: break; } } }