public override void Initialize() { AssertPermission(GuildPermission.ManageChannels); _commandSet = new VoiceNameSet { ParentPlugin = this }; GuildHandler.ChannelCreated += OnChannelCreated; GuildHandler.ChannelDestroyed += OnChannelDestroyed; GuildHandler.UserVoiceStateUpdated += OnVoiceStateUpdated; GuildHandler.GuildMemberUpdated += OnGuildMemberUpdated; GuildHandler.ChannelUpdated += OnChannelUpdated; InitDefaultTags(); _channelNames = GetConfigCache("ChannelNames", x => x.GetGuild().VoiceChannels.ToDictionary(y => y.Id, z => z.Name)); _channelNames.Store(); _toIgnore = GetConfigCache("ToIgnore", x => new List <ulong> { (x.GetGuild().AFKChannel?.Id).GetValueOrDefault() }); _musicBotId = GetConfigCache("MusicBotId", x => (ulong)0); _internationalRoleId = GetConfigCache("MusicBotId", x => (ulong)0); _nameFormat = GetConfigCache("NameFormat", x => $"{_formatStart}{_formatNameStr}{_formatEnd} - {_formatStart}{_formatGameStr}{_formatEnd} {_formatStart}({_formatAmountPlayersStr}){_formatEnd}"); // lol _shortenedGameNames = GetConfigCache("ShortenedGameNames", x => new Dictionary <string, string>()); AddConfigInfo("Set Channel Name", "Display channel names", () => "Current channel names:\n" + string.Join('\n', _channelNames.GetValue().Select(x => x.Value).ToArray())); AddConfigInfo <SocketVoiceChannel, string>("Set Channel Name", "Set channel name", (x, y) => _channelNames.MutateValue(z => z[x.Id] = y), (success, x, y) => $"Succesfully set channel '{x.Name}' to '{y}'", "Channel", "New name"); AddConfigInfo <string, string>("Set Channel Name", "Set channel name", (x, y) => _channelNames.MutateValue(z => z[GuildHandler.GetVoiceChannel(x).Id] = y), (success, x, y) => "Succesfully set channel names.", "Channel", "New name"); AddConfigInfo <SocketVoiceChannel>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(x.Id)), (success, x) => $"Added channel '{x.Name}' to list of ignored channels.", "Channel"); AddConfigInfo <ulong>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Added channel '{GuildHandler.GetVoiceChannel (x).Name}' to list of ignored channels.", "ignored"); AddConfigInfo <string>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Added channel '{GuildHandler.GetVoiceChannel(x).Name}' to list of ignored channels.", "Channel"); AddConfigInfo <SocketVoiceChannel>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(x.Id)), (success, x) => $"Removed channel '{x.Name}' from list of ignored.", "Channel"); AddConfigInfo <ulong>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel"); AddConfigInfo <string>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel"); AddConfigInfo <SocketGuildUser>("Set Music Bot", "Set music bot.", x => _musicBotId.SetValue(x.Id), (success, x) => $"Set music bot to be {x.Id}.", "Music Bot"); AddConfigInfo <string>("Set Music Bot", "Set music bot.", x => _musicBotId.SetValue(GuildHandler.GetUser(x).Id), (success, x) => $"Set music bot to be {GuildHandler.GetUser(x).GetShownName()}.", "Music Bot"); AddConfigInfo("Set Music Bot", "Show music bot.", () => GuildHandler.FindUser(_musicBotId.GetValue()) == null ? "Current music bot doesn't exist :(" : "Current music bot is " + GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()); AddConfigInfo <SocketRole>("Set International Role", "Set role.", x => _internationalRoleId.SetValue(x.Id), (success, x) => $"Set international role to be {x}.", "Role"); AddConfigInfo <string>("Set International Role", "Set role.", x => _internationalRoleId.SetValue(GuildHandler.GetRole(x).Id), (success, x) => $"Set international role to be {GuildHandler.GetRole(x).Name}.", "Role Name"); AddConfigInfo("Set International Role", "Show role.", () => GuildHandler.FindRole(_internationalRoleId.GetValue()) == null ? "Current international role doesn't exist :(" : "Current international role is " + GuildHandler.GetRole(_internationalRoleId.GetValue()).Name); AddConfigInfo("Set Name Format", "Set format", () => $"Current format is '{_nameFormat.GetValue()}' which might look like this in practice: '{FormatName(_nameFormat.GetValue(), _formatStart, _formatEnd, "General 1", "Cool Game 3: The Coolest", 5)}'."); AddConfigInfo <string>("Set Name Format", "Set format", x => _nameFormat.SetValue(x), (success, x) => $"Set format to '{x}' which might look like this in practice: '{FormatName(x, _formatStart, _formatEnd, "General 1", "Cool Game 3: The Coolest", 5)}'.", "Format"); AddConfigInfo <string, string>("Shorten Game Name", "Shorten a games name", (x, y) => SetShortenedGameName(x, y), (success, x, y) => $"'{x}' will now be shortened to '{y}'.", "Game", "Name"); SendMessage("Moduthulhu-Command Root", "AddCommand", _commandSet); AddGeneralFeaturesStateAttribute("AutomatedVoiceNames", "Automatically changing voice channel names to reflect games played within."); RegisterMessageAction("AddTag", x => AddTag(new Tag((string)x[0], (string)x[1], (Func <SocketVoiceChannel, bool>)x[2]))); RegisterMessageAction("RemoveTag", x => RemoveTag((string)x[0])); SetStateChangeHeaders("Tags", "The following voice channel tags has been added", "The following voice channel tags has been removed", "The following voice channel tags has been modified"); RegisterMessageAction("UpdateChannel", x => UpdateChannel(GuildHandler.GetVoiceChannel((ulong)x[0])).ConfigureAwait(false)); }
private async Task UpdateUser(ulong user) { DisablePluginIfPermissionMissing(GuildPermission.ManageRoles, true); DateTime activity = GetLastActivity(user); ulong role = GetRole(_activityRoles.GetValue(), activity); SocketRole roleObj = GuildHandler.FindRole(role); if (roleObj != null) { SocketGuildUser userObj = GuildHandler.GetUser(user); List <SocketRole> toRemove = userObj.Roles.Where(x => _activityRoles.GetValue().Any(y => x.Id == y.Id)).ToList(); toRemove.Remove(roleObj); if (!userObj.Roles.Contains(roleObj)) { Core.Log.User($"Adding activity role {roleObj.Name} to {userObj.GetShownName ()}"); await userObj.AsyncSecureAddRole(roleObj); } foreach (var toRemoveRole in toRemove) { Core.Log.User($"Removing activity role {toRemoveRole.Name} from {userObj.GetShownName()}"); await userObj.AsyncSecureRemoveRole(toRemoveRole); } } }
private string GetSnowflakeName(ulong id) { IUser user = GuildHandler.FindUser(id); if (user != null) { return($"@{user.GetShownName ()}"); } IChannel channel = GuildHandler.FindChannel(id); if (channel != null) { return($"#{channel.Name}"); } IRole role = GuildHandler.FindRole(id); if (role != null) { return($"@{role.Name}"); } return(id.ToString()); }
public override void Initialize() { GuildHandler.MessageReceived += DiscordClient_MessageReceived; GuildHandler.UserVoiceStateUpdated += DiscordClient_UserVoiceStateUpdated; GuildHandler.UserJoined += DiscordClient_UserJoined; AddConfigInfo("Add Activity Role", "Add new role.", new Action <SocketRole, uint>((x, y) => _activityRoles.MutateValue(z => AddRole(new ActivityRole((x?.Id).GetValueOrDefault(), y)))), () => "Added new activity role", "Role", "Treshold (days)"); AddConfigInfo("Add Activity Role", "Add new role.", new Action <ulong, uint>((x, y) => _activityRoles.MutateValue(z => AddRole(new ActivityRole(x, y)))), () => "Added new activity role", "Role", "Treshold (days)"); AddConfigInfo("Add Activity Role", "Add new role.", new Action <string, uint>((x, y) => _activityRoles.MutateValue(z => AddRole(new ActivityRole((GuildHandler.FindRole(x)?.Id).GetValueOrDefault(), y)))), () => "Added new activity role", "Role", "Treshold (days)"); AddConfigInfo("Add Activity Role", "Display roles", () => "Current activity roles:\n" + string.Join("\n", _activityRoles.GetValue().Select(x => x.ToString(GuildHandler)).ToArray())); AddConfigInfo("Remove Activity Role", "Remove role.", new Action <SocketRole>((x) => _activityRoles.MutateValue(z => z.RemoveAll(w => w.id == x.Id))), () => "Removed activity role", "Role"); AddConfigInfo("Remove Activity Role", "Remove role.", new Action <string>((x) => _activityRoles.MutateValue(z => z.RemoveAll(w => w.id == GuildHandler.FindRole(x).Id))), () => "Removed activity role", "Role"); AddConfigInfo("Remove Activity Role", "Remove role.", new Action <uint>((x) => _activityRoles.MutateValue(z => z.RemoveAll(w => w.id == x))), () => "Removed activity role", "Role"); _userActivity = GetDataCache("UserActivity", x => new Dictionary <ulong, DateTime>()); _activityRoles = GetConfigCache("ActivityRoles", x => new List <ActivityRole>()); GuildHandler.Clock.OnDayPassed += CheckAll; }
public override void Initialize() { commandSet = new VoiceNameSet() { ParentPlugin = this }; GuildHandler.ChannelCreated += OnChannelCreated; GuildHandler.ChannelDestroyed += OnChannelDestroyed; GuildHandler.UserVoiceStateUpdated += OnVoiceStateUpdated; GuildHandler.GuildMemberUpdated += OnGuildMemberUpdated; InitDefaultTags(); _channelNames = GetConfigCache("ChannelNames", x => x.GetGuild().VoiceChannels.ToDictionary(y => y.Id, z => z.Name)); _toIgnore = GetConfigCache("ToIgnore", x => new List <ulong>() { (x.GetGuild().AFKChannel?.Id).GetValueOrDefault() }); //_nameFormat = GetConfigCache("NameFormat", x => "[TAGS][NAME] - [GAME]"); _musicBotId = GetConfigCache("MusicBotId", x => (ulong)0); _internationalRoleId = GetConfigCache("MusicBotId", x => (ulong)0); AddConfigInfo("Set Channel Name", "Display channel names", () => "Current channel names:\n" + string.Join('\n', _channelNames.GetValue().Select(x => x.Value).ToArray())); AddConfigInfo("Set Channel Name", "Set channel name", new Action <SocketVoiceChannel, string>((x, y) => _channelNames.MutateValue(z => z[x.Id] = y)), () => "Succesfully set channel names.", "Channel", "New name"); AddConfigInfo("Set Channel Name", "Set channel name", new Action <string, string>((x, y) => _channelNames.MutateValue(z => z[GuildHandler.FindVoiceChannel(x).Id] = y)), () => "Succesfully set channel names.", "Channel", "New name"); AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <SocketVoiceChannel>((x) => _toIgnore.MutateValue(y => y.Add(x.Id))), () => "Added channel to list of ignored.", "Channel"); AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <ulong>((x) => _toIgnore.MutateValue(y => y.Add(x))), () => "Added channel to list of default.", "ignored"); AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <string>((x) => _toIgnore.MutateValue(y => y.Add(GuildHandler.FindVoiceChannel(x).Id))), () => "Added channel to list of ignored.", "Channel"); AddConfigInfo("Do Name Channel", "Unignore channel", new Action <SocketVoiceChannel>((x) => _toIgnore.MutateValue(y => y.Remove(x.Id))), () => "Removed channel from list of ignored.", "Channel"); AddConfigInfo("Do Name Channel", "Unignore channel", new Action <ulong>((x) => _toIgnore.MutateValue(y => y.Remove(x))), () => "Removed channel from list of ignored.", "Channel"); AddConfigInfo("Do Name Channel", "Unignore channel", new Action <string>((x) => _toIgnore.MutateValue(y => y.Remove(GuildHandler.FindVoiceChannel(x).Id))), () => "Removed channel from list of ignored.", "Channel"); AddConfigInfo("Set Music Bot", "Set music bot.", new Action <SocketGuildUser>((x) => _musicBotId.SetValue(x.Id)), () => $"Set music bot to be {GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()}.", "Music Bot"); AddConfigInfo("Set Music Bot", "Set music bot.", new Action <string>((x) => _musicBotId.SetValue(GuildHandler.FindUser(x).Id)), () => $"Set music bot to be {GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()}.", "Music Bot"); AddConfigInfo("Set Music Bot", "Show music bot.", () => GuildHandler.GetUser(_musicBotId.GetValue()) == null ? "Current music bot doesn't exist :(" : "Current music bot is " + GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()); AddConfigInfo("Set International Role", "Set role.", new Action <SocketRole>((x) => _internationalRoleId.SetValue(x.Id)), () => $"Set international role to be {GuildHandler.GetRole(_internationalRoleId.GetValue()).Name}.", "Role"); AddConfigInfo("Set International Role", "Set role.", new Action <string>((x) => _internationalRoleId.SetValue(GuildHandler.FindRole(x).Id)), () => $"Set international role to be {GuildHandler.GetRole(_internationalRoleId.GetValue()).Name}.", "Role Name"); AddConfigInfo("Set International Role", "Show role.", () => GuildHandler.GetRole(_internationalRoleId.GetValue()) == null ? "Current international role doesn't exist :(" : "Current international role is " + GuildHandler.GetRole(_internationalRoleId.GetValue()).Name); SendMessage("Lomztein-Command Root", "AddCommand", commandSet); }
private List <ActivityRole> FilterMissing(List <ActivityRole> current) => current.Where(x => GuildHandler.FindRole(x.Id) != null).ToList();