public string GenerateContractedName(GuildHandler nameSource) { SocketGuildUser one = nameSource.GetUser(ShippieOne); SocketGuildUser two = nameSource.GetUser(ShippieTwo); int maxLength = Math.Max(one.GetShownName().Length, two.GetShownName().Length); string firstPart = GetPartName(one.GetShownName(), true, maxLength); string lastPart = GetPartName(two.GetShownName(), false, maxLength); return(firstPart + lastPart); }
private async Task TestBirthdays() { bool hasChanged = false; foreach (var user in _allBirthdays.GetValue()) { if (user.Value.IsNow()) { SocketGuildUser guildUser = GuildHandler.GetUser(user.Key); if (guildUser == null) { return; // User doesn't exist anymore, may have left the server. } SocketTextChannel guildChannel = GuildHandler.GetTextChannel(_announcementChannel.GetValue()); await AnnounceBirthday(guildChannel, guildUser, user.Value); user.Value.SetLastPassedToNow(); hasChanged = true; } } if (hasChanged) { _allBirthdays.Store(); } }
public string ShipToString(Ship ship) { SocketGuildUser one = GuildHandler.GetUser(ship.ShippieOne); SocketGuildUser two = GuildHandler.GetUser(ship.ShippieTwo); return($"{one.GetShownName()} x {two.GetShownName()} - {GetShipName(ship)}"); }
public string ToString(GuildHandler guildHandler) { return($"Trigger: {Trigger}, " + "User: "******"Any" : guildHandler.GetUser(UserId).GetShownName()) + ", " + "Channel: " + (guildHandler.FindTextChannel(ChannelId) == null ? "Any" : guildHandler.FindTextChannel(ChannelId).Name) + ", " + $"Chance: {Math.Round(Chance, 2)}%, Response: {Response}, Emote: {Emoji}"); }
private string PhraseToString(Phrase phrase) { return($"Trigger: {phrase.triggerPhrase}, " + "User: "******"Any" : GuildHandler.GetUser(phrase.userID).GetShownName()) + ", " + "Channel: " + (GuildHandler.GetChannel(phrase.channelID) == null ? "Any" : GuildHandler.GetChannel(phrase.channelID).Name) + ", " + $"Chance: {Math.Round (phrase.chance, 2)}%, Response: {phrase.response}, Emote: {phrase.emoji}"); }
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); } } }
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 static EmbedFieldBuilder GetTopVoters(Func <int, int, int> comparer, ulong[] voters, string title, string type, string ifNone, int topCount, GuildHandler guildHandler) { var sorted = voters.Distinct().ToList(); var dict = sorted.ToDictionary(x => x, x => voters.Count(y => x == y)).ToList(); dict.Sort(new Comparison <KeyValuePair <ulong, int> > ((x, y) => comparer(x.Value, y.Value))); int count = sorted.Count(); var voterList = dict.ToList().GetRange(0, Math.Min(count, topCount)); StringBuilder top = new StringBuilder("```"); foreach (var upvote in voterList) { IUser user = guildHandler.GetUser(upvote.Key); string name = user == null ? "*User not found." : user.GetShownName(); top.AppendLine($"{name} - {upvote.Value} {type}."); } top.AppendLine("```"); return(new EmbedFieldBuilder().WithName(title).WithValue(count == 0 ? ifNone : top.ToString())); }
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 => $"{_formatNameStr} - {_formatGameStr} ({_formatAmountPlayersStr})"); 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), (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), (x, y) => "Succesfully set channel names.", "Channel", "New name"); AddConfigInfo <SocketVoiceChannel>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(x.Id)), 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)), 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)), 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)), 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)), 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)), x => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel"); AddConfigInfo <SocketGuildUser>("Set Music Bot", "Set music bot.", x => _musicBotId.SetValue(x.Id), 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), 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), x => $"Set international role to be {x}.", "Role"); AddConfigInfo <string>("Set International Role", "Set role.", x => _internationalRoleId.SetValue(GuildHandler.GetRole(x).Id), 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(), "General 1", "Cool Game 3: The Coolest", 5)}'."); AddConfigInfo <string>("Set Name Format", "Set format", x => _nameFormat.SetValue(x), x => $"Set format to '{x}' which might look like this in practice: '{FormatName(x, "General 1", "Cool Game 3: The Coolest", 5)}'.", "Format"); 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)); }
public override void Initialize() { GuildHandler.MessageReceived += OnMessageRecieved; _phrases = GetConfigCache("Phrases", x => new List <Phrase>()); #region AddConfigInfo("Add Phrase", "Add empty phrase.", () => { _phrases.GetValue().Add(new Phrase()); _phrases.Store(); }, () => $"Added new empty response phrase at index {_phrases.GetValue ().Count - 1}. You must edit it using the other config options available here."); AddConfigInfo <int>("Remove Phrase", "Remove phrase.", x => { _phrases.GetValue().RemoveAt(x); _phrases.Store(); }, x => $"Removed response phrase at the index {x}.", "Index"); AddConfigInfo("List Phrases", "List current phrases.", () => "Current phrases:\n" + string.Join('\n', _phrases.GetValue().Select(x => _phrases.GetValue().IndexOf(x) + " -> " + x.ToString(GuildHandler)))); AddConfigInfo("Set Phrase Trigger", "Set trigger", () => { _phrases.GetValue().LastOrDefault().Trigger = string.Empty; _phrases.Store(); }, () => $"Most recent phrase trigger reset."); AddConfigInfo <string>("Set Phrase Trigger", "Set trigger", y => { _phrases.GetValue().LastOrDefault().Trigger = y; _phrases.Store(); }, y => $"Most recent phrase trigger set to {y}.", "Trigger"); AddConfigInfo <int>("Set Phrase Trigger", "Set trigger", x => { _phrases.GetValue()[x].Trigger = string.Empty; _phrases.Store(); }, x => $"Phrase trigger at index {x} reset.", "Index"); AddConfigInfo <int, string>("Set Phrase Trigger", "Set trigger", (x, y) => { _phrases.GetValue()[x].Trigger = y; _phrases.Store(); }, (x, y) => $"Phrase trigger at index {x} updated to '{y}'.", "Index", "Trigger"); AddConfigInfo("Set Phrase User", "Set user", () => { _phrases.GetValue().LastOrDefault().UserId = 0; _phrases.Store(); }, () => $"Most recent phrase user reset."); AddConfigInfo <SocketGuildUser>("Set Phrase User", "Set user", y => { _phrases.GetValue().LastOrDefault().UserId = y.Id; _phrases.Store(); }, x => $"Most recent phrase user updated to '{x.GetShownName ()}'.", "User"); AddConfigInfo <string>("Set Phrase User", "Set user", y => { _phrases.GetValue().LastOrDefault().UserId = GuildHandler.GetUser(y).Id; _phrases.Store(); }, y => $"Most recent phrase user updated to '{GuildHandler.GetUser (y).GetShownName ()}'.", "Username"); AddConfigInfo <ulong>("Set Phrase User", "Set user", y => { _phrases.GetValue().LastOrDefault().UserId = y; _phrases.Store(); }, y => $"Most recent phrase user updated to '{GuildHandler.GetUser (y).GetShownName ()}.", "User ID"); AddConfigInfo <int>("Set Phrase User", "Set user", x => { _phrases.GetValue()[x].UserId = 0; _phrases.Store(); }, x => $"Phrase user at index {x} reset.", "Index"); AddConfigInfo <int, SocketGuildUser>("Set Phrase User", "Set user", (x, y) => { _phrases.GetValue()[x].UserId = y.Id; _phrases.Store(); }, (x, y) => $"Phrase user at index {x} updated to '{y.GetShownName()}'.", "Index", "User"); AddConfigInfo <int, string>("Set Phrase User", "Set user", (x, y) => { _phrases.GetValue()[x].UserId = GuildHandler.FindUser(y).Id; _phrases.Store(); }, (x, y) => $"Phrase user at index {x} updated to '{GuildHandler.GetUser (y).GetShownName ()}'.", "Index", "Username"); AddConfigInfo <int, ulong>("Set Phrase User", "Set user", (x, y) => { _phrases.GetValue()[x].UserId = y; _phrases.Store(); }, (x, y) => $"Phrase user at index {x} updated to '{GuildHandler.GetUser(y).GetShownName ()}'.", "Index", "User ID"); AddConfigInfo("Set Phrase Channel", "Set channel", () => { _phrases.GetValue().LastOrDefault().ChannelId = 0; _phrases.Store(); }, () => $"Most recent phrase channel reset."); AddConfigInfo <SocketTextChannel>("Set Phrase Channel", "Set channel", y => { _phrases.GetValue().LastOrDefault().ChannelId = y.Id; _phrases.Store(); }, x => $"Most recent phrase channel updated to '{x.Name}'.", "Channel"); AddConfigInfo <string>("Set Phrase Channel", "Set channel", y => { _phrases.GetValue().LastOrDefault().ChannelId = GuildHandler.GetTextChannel(y).Id; _phrases.Store(); }, x => $"Most recent phrase channel updated to '{GuildHandler.GetTextChannel (x).Name}'.", "Channel Name"); AddConfigInfo <ulong>("Set Phrase Channel", "Set channel", y => { _phrases.GetValue().LastOrDefault().ChannelId = y; _phrases.Store(); }, x => $"Most recent phrase channel updated to '{GuildHandler.GetTextChannel (x).Name}'.", "Channel ID"); AddConfigInfo <int>("Set Phrase Channel", "Set channel", x => { _phrases.GetValue()[x].ChannelId = 0; _phrases.Store(); }, x => $"Phrase channel at index {x} reset.", "Index"); AddConfigInfo <int, SocketTextChannel>("Set Phrase Channel", "Set channel", (x, y) => { _phrases.GetValue()[x].ChannelId = y.Id; _phrases.Store(); }, (x, y) => $"Phrase channel at index {x} updated to '{y.Name}'.", "Index", "Channel"); AddConfigInfo <int, string>("Set Phrase Channel", "Set channel", (x, y) => { _phrases.GetValue()[x].ChannelId = GuildHandler.GetTextChannel(y).Id; _phrases.Store(); }, (x, y) => $"Phrase channel at index {x} updated to '{GuildHandler.GetTextChannel(y).Name}'.", "Index", "Channel Name"); AddConfigInfo <int, ulong>("Set Phrase Channel", "Set channel", (x, y) => { _phrases.GetValue()[x].ChannelId = y; _phrases.Store(); }, (x, y) => $"Phrase channel at index {x} '{GuildHandler.GetTextChannel (y)}'.", "Index", "Channel ID"); AddConfigInfo("Set Phrase Chance", "Set chance", () => { _phrases.GetValue().LastOrDefault().Chance = 0; _phrases.Store(); }, () => $"Most recent chance reset."); AddConfigInfo <double>("Set Phrase Chance", "Set chance", y => { _phrases.GetValue().LastOrDefault().Chance = Math.Clamp(y, 0d, 100d); _phrases.Store(); }, y => $"Most recent phrase chance updated to {y}.", "Chance"); AddConfigInfo("Set Phrase Response", "Set response", () => { _phrases.GetValue().LastOrDefault().Response = string.Empty; _phrases.Store(); }, () => $"Most recent phrase response reset."); AddConfigInfo <string>("Set Phrase Response", "Set response", y => { _phrases.GetValue().LastOrDefault().Response = y; _phrases.Store(); }, x => $"Most recent phrase response updated {x}.", "Response"); AddConfigInfo("Set Phrase Emoji", "Set emoji", () => { _phrases.GetValue().LastOrDefault().Emoji = string.Empty; _phrases.Store(); }, () => $"Most recent phrase emoji reset."); AddConfigInfo <string>("Set Phrase Emoji", "Set emoji", y => { _phrases.GetValue().LastOrDefault().Emoji = y; _phrases.Store(); }, x => $"Most recent phrase emoji updated {x}.", "Emoji"); AddConfigInfo <int>("Set Phrase Chance", "Set chance", x => { _phrases.GetValue()[x].Chance = 100; _phrases.Store(); }, x => $"Phrase at index {x} chance reset.", "Index"); AddConfigInfo <int, double>("Set Phrase Chance", "Set chance", (x, y) => { _phrases.GetValue()[x].Chance = Math.Clamp(y, 0d, 100d); _phrases.Store(); }, (x, y) => $"Phrase at index {x} chance updated to {y}.", "Index", "Chance"); AddConfigInfo <int>("Set Phrase Response", "Set response", x => { _phrases.GetValue()[x].Response = string.Empty; _phrases.Store(); }, x => $"Phrase at index {x} response reset.", "Index"); AddConfigInfo <int, string>("Set Phrase Response", "Set response", (x, y) => { _phrases.GetValue()[x].Response = y; _phrases.Store(); }, (x, y) => $"Phrase at index {x} response updated to {y}.", "Index", "Response"); AddConfigInfo <int>("Set Phrase Emoji", "Set emoji", x => { _phrases.GetValue()[x].Emoji = string.Empty; _phrases.Store(); }, x => $"Phrase at index {x} emoji reset.", "Index"); AddConfigInfo <int, string>("Set Phrase Emoji", "Set emoji", (x, y) => { _phrases.GetValue()[x].Emoji = y; _phrases.Store(); }, (x, y) => $"Phrase at index {x} emoji updated to {y}.", "Index", "Emoji"); #endregion AddGeneralFeaturesStateAttribute("AutomatedPhrases", "Automatic response to certain phrases as configured."); }