/// <summary>
        /// Changes a guilds color
        /// </summary>
        /// <param name="guild">Guild to update</param>
        /// <param name="newColor">New color to apply</param>
        /// <returns>true, if operation succeeds</returns>
        public static async Task <bool> UpdateGuildColorAsync(MinecraftGuild guild, GuildColor newColor)
        {
            string errorhint = "Modifying Guild Role";

            try
            {
                if (BotCore.Client.TryGetRole(guild.RoleId, out SocketRole guildRole))
                {
                    await guildRole.ModifyAsync(RoleProperties =>
                    {
                        RoleProperties.Color = MinecraftGuild.ToDiscordColor(newColor);
                    });

                    errorhint   = "Setting Guild Color";
                    guild.Color = newColor;
                    errorhint   = "Notify Admins";
                    await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Change color of guild \"{guild.Name}\" to \"{newColor}\" ingame", $"Color: `{ newColor}` (`0x{ ((uint)newColor).ToString("X")}`)");

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                await GuildChannelHelper.SendExceptionNotification(e, $"Error recoloring guild {guild.Name} to {newColor}. Hint: {errorhint}");

                return(false);
            }
        }
Example #2
0
 /// <summary>
 /// Converts a guild color to a discord color
 /// </summary>
 public static Color ToDiscordColor(GuildColor color)
 {
     if (color == GuildColor.black)
     {
         return(new Color(DISCORDBLACK));
     }
     return(new Color((uint)color));
 }
Example #3
0
 public MinecraftGuild(ulong channelId, ulong roleId, GuildColor color, string name, ulong captainId)
 {
     ChannelId             = channelId;
     RoleId                = roleId;
     Color                 = color;
     Name                  = name;
     CaptainId             = captainId;
     nameAndColorRetrieved = true;
     FoundingTimestamp     = DateTimeOffset.UtcNow;
 }
Example #4
0
 /// <summary>
 /// Tries to find Name and Color by retrieving the guilds role
 /// </summary>
 /// <returns>True if name and color could be retrieved</returns>
 public bool TryFindNameAndColor()
 {
     if (BotCore.Client.TryGetRole(RoleId, out SocketRole guildRole) && !nameAndColorRetrieved)
     {
         Color = (GuildColor)guildRole.Color.RawValue;
         if (guildRole.Color.RawValue == DISCORDBLACK)
         {
             Color = GuildColor.black;
         }
         Name = guildRole.Name;
         nameAndColorRetrieved = true;
         return(true);
     }
     return(false);
 }
Example #5
0
        public void Save()
        {
            if (_filestream == null)
            {
                return;
            }


            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("window"));

            xml.Root.Add(new XElement("location"));
            xml.Root.Element("location").Add(new XElement("x", Location.X.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Element("location").Add(new XElement("y", Location.Y.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("language", Language));
            xml.Root.Add(new XElement("ui_language", UILanguage));
            xml.Root.Add(new XElement("opacity"));
            xml.Root.Element("opacity").Add(new XElement("mainWindow", MainWindowOpacity * 100));
            xml.Root.Element("opacity").Add(new XElement("skillWindow", SkillWindowOpacity * 100));
            xml.Root.Add(new XElement("autoupdate", AutoUpdate));
            xml.Root.Add(new XElement("remember_position", RememberPosition));
            xml.Root.Add(new XElement("winpcap", Winpcap));
            xml.Root.Add(new XElement("invisible_ui_when_no_stats", InvisibleUi));
            xml.Root.Add(new XElement("allow_transparency", AllowTransparency));
            xml.Root.Add(new XElement("topmost", Topmost));
            xml.Root.Add(new XElement("debug", Debug));
            xml.Root.Add(new XElement("excel", Excel));
            xml.Root.Add(new XElement("excel_path_template", ExcelPathTemplate));
            xml.Root.Add(new XElement("excel_save_directory", ExcelSaveDirectory));
            xml.Root.Add(new XElement("excel_cma_dps_seconds", ExcelCMADPSSeconds));
            xml.Root.Add(new XElement("always_visible", AlwaysVisible));
            xml.Root.Add(new XElement("scale", Scale.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("lf_delay", LFDelay));
            xml.Root.Add(new XElement("partyonly", PartyOnly));
            xml.Root.Add(new XElement("showhealcrit", ShowHealCrit));
            xml.Root.Add(new XElement("showtimeleft", ShowTimeLeft));
            xml.Root.Add(new XElement("show_crit_damage_rate", ShowCritDamageRate));
            xml.Root.Add(new XElement("detect_bosses_only_by_hp_bar", DetectBosses));
            xml.Root.Add(new XElement("only_bosses", OnlyBoss));
            xml.Root.Add(new XElement("low_priority", LowPriority));
            xml.Root.Add(new XElement("number_of_players_displayed", NumberOfPlayersDisplayed));
            xml.Root.Add(new XElement("meter_user_on_top", MeterUserOnTop));
            xml.Root.Add(new XElement("remove_tera_alt_enter_hotkey", RemoveTeraAltEnterHotkey));
            xml.Root.Add(new XElement("enable_chat_and_notifications", EnableChat));
            xml.Root.Add(new XElement("mute_sound", MuteSound));
            xml.Root.Add(new XElement("copy_inspect", CopyInspect));
            xml.Root.Add(new XElement("format_paste_string", FormatPasteString));
            xml.Root.Add(new XElement("say_color", SayColor.ToString()));
            xml.Root.Add(new XElement("alliance_color", AllianceColor.ToString()));
            xml.Root.Add(new XElement("area_color", AreaColor.ToString()));
            xml.Root.Add(new XElement("guild_color", GuildColor.ToString()));
            xml.Root.Add(new XElement("whisper_color", WhisperColor.ToString()));
            xml.Root.Add(new XElement("general_color", GeneralColor.ToString()));
            xml.Root.Add(new XElement("group_color", GroupColor.ToString()));
            xml.Root.Add(new XElement("trading_color", TradingColor.ToString()));
            xml.Root.Add(new XElement("emotes_color", EmotesColor.ToString()));
            xml.Root.Add(new XElement("private_channel_color", PrivateChannelColor.ToString()));
            xml.Root.Add(new XElement("disable_party_event", DisablePartyEvent));
            xml.Root.Add(new XElement("show_afk_events_ingame", ShowAfkEventsIngame));
            xml.Root.Add(new XElement("idle_reset_timeout", IdleResetTimeout));

            xml.Root.Add(new XElement("teradps.io"));
            xml.Root.Element("teradps.io").Add(new XElement("user", TeraDpsUser));
            xml.Root.Element("teradps.io").Add(new XElement("token", TeraDpsToken));
            xml.Root.Element("teradps.io").Add(new XElement("enabled", SiteExport));
            xml.Root.Element("teradps.io").Add(new XElement("private_servers", new XAttribute("enabled", PrivateServerExport)));
            PrivateDpsServers.ForEach(x =>
                                      xml.Root.Element("teradps.io").Element("private_servers").Add(new XElement("server", x))
                                      );

            _filestream.SetLength(0);
            using (var sw = new StreamWriter(_filestream, new UTF8Encoding(true)))
            {
                sw.Write(xml.Declaration + Environment.NewLine + xml);
            }
            _filestream.Close();
        }
Example #6
0
        public void Save()
        {
            if (_filestream == null)
            {
                return;
            }


            var xml = new XDocument(new XElement("window"));

            xml.Root.Add(new XElement("location"));
            xml.Root.Element("location").Add(new XElement("x", Location.X.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Element("location").Add(new XElement("y", Location.Y.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("language", Language));
            xml.Root.Add(new XElement("ui_language", UILanguage));
            xml.Root.Add(new XElement("opacity"));
            xml.Root.Element("opacity").Add(new XElement("mainWindow", MainWindowOpacity * 100));
            xml.Root.Element("opacity").Add(new XElement("skillWindow", SkillWindowOpacity * 100));
            xml.Root.Add(new XElement("autoupdate", AutoUpdate));
            xml.Root.Add(new XElement("remember_position", RememberPosition));
            xml.Root.Add(new XElement("winpcap", Winpcap));
            xml.Root.Add(new XElement("invisible_ui_when_no_stats", InvisibleUi));
            xml.Root.Add(new XElement("allow_transparency", AllowTransparency));
            xml.Root.Add(new XElement("topmost", Topmost));
            xml.Root.Add(new XElement("teradps.io"));
            xml.Root.Element("teradps.io").Add(new XElement("user", TeraDpsUser));
            xml.Root.Element("teradps.io").Add(new XElement("token", TeraDpsToken));
            xml.Root.Element("teradps.io").Add(new XElement("enabled", SiteExport));
            xml.Root.Add(new XElement("debug", Debug));
            xml.Root.Add(new XElement("excel", Excel));
            xml.Root.Add(new XElement("date_in_excel_path", DateInExcelPath));
            xml.Root.Add(new XElement("excel_save_directory", ExcelSaveDirectory));
            xml.Root.Add(new XElement("always_visible", AlwaysVisible));
            xml.Root.Add(new XElement("scale", Scale.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("lf_delay", LFDelay));
            xml.Root.Add(new XElement("partyonly", PartyOnly));
            xml.Root.Add(new XElement("showhealcrit", ShowHealCrit));
            xml.Root.Add(new XElement("detect_bosses_only_by_hp_bar", DetectBosses));
            xml.Root.Add(new XElement("only_bosses", OnlyBoss));
            xml.Root.Add(new XElement("low_priority", LowPriority));
            xml.Root.Add(new XElement("number_of_players_displayed", NumberOfPlayersDisplayed));

            xml.Root.Add(new XElement("notify_sound", NotifySound));
            xml.Root.Add(new XElement("volume", Volume));
            xml.Root.Add(new XElement("popup_display_time", PopupDisplayTime));
            xml.Root.Add(new XElement("sound_notify_duration", SoundNotifyDuration));

            xml.Root.Add(new XElement("say_color", SayColor.ToString()));
            xml.Root.Add(new XElement("alliance_color", AllianceColor.ToString()));
            xml.Root.Add(new XElement("area_color", AreaColor.ToString()));
            xml.Root.Add(new XElement("guild_color", GuildColor.ToString()));
            xml.Root.Add(new XElement("whisper_color", WhisperColor.ToString()));
            xml.Root.Add(new XElement("general_color", GeneralColor.ToString()));
            xml.Root.Add(new XElement("group_color", GroupColor.ToString()));
            xml.Root.Add(new XElement("trading_color", TradingColor.ToString()));
            xml.Root.Add(new XElement("emotes_color", EmotesColor.ToString()));
            xml.Root.Add(new XElement("private_channel_color", PrivateChannelColor.ToString()));
            xml.Root.Add(new XElement("remove_tera_alt_enter_hotkey", RemoveTeraAltEnterHotkey));
            xml.Root.Add(new XElement("enable_chat_and_notifications", EnableChat));
            xml.Root.Add(new XElement("copy_inspect", CopyInspect));

            _filestream.SetLength(0);
            using (var sr = new StreamWriter(_filestream))
            {
                // File writing as usual
                sr.Write(xml);
            }
            _filestream.Close();
        }
 /// <summary>
 /// Returns true if the color provided is still available
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 public static bool ColorIsAvailable(GuildColor color)
 {
     return(AvailableColors.Contains(color));
 }
        /// <summary>
        /// Creates a new guild (includes role, channel, etc)
        /// </summary>
        /// <param name="guild">Discord Server Guild to create channel and role on</param>
        /// <param name="name">Guild Name</param>
        /// <param name="color">Guild Display Color</param>
        /// <param name="captain">Guild Captain</param>
        /// <param name="members">Guild Users</param>
        /// <returns>true, if operation succeeds</returns>
        public static async Task <bool> CreateGuildAsync(SocketGuild guild, string name, GuildColor color, SocketGuildUser captain, List <SocketGuildUser> members)
        {
            string errorhint = "Failed a precheck";

            try
            {
                if (TryGetGuildOfUser(captain.Id, out MinecraftGuild existingCaptainGuild))
                {
                    if (existingCaptainGuild.Active || captain.Id == existingCaptainGuild.CaptainId)
                    {
                        errorhint = "Precheck failed on " + captain.Mention;
                        return(false);
                    }
                    else
                    {
                        existingCaptainGuild.MateIds.Remove(captain.Id);
                        existingCaptainGuild.MemberIds.Remove(captain.Id);
                    }
                }
                foreach (SocketGuildUser member in members)
                {
                    if (TryGetGuildOfUser(member.Id, out MinecraftGuild existingMemberGuild))
                    {
                        if (existingCaptainGuild.Active || member.Id == existingCaptainGuild.CaptainId)
                        {
                            return(false);
                        }
                        else
                        {
                            errorhint = "Precheck failed on " + member.Mention;
                            existingCaptainGuild.MateIds.Remove(member.Id);
                            existingCaptainGuild.MemberIds.Remove(member.Id);
                        }
                    }
                }
                errorhint = "Failed to create Guild Role!";
                RestRole guildRole = await guild.CreateRoleAsync(name, color : MinecraftGuild.ToDiscordColor(color), isHoisted : true);

                errorhint = "Move role into position";
                await guildRole.ModifyAsync(RoleProperties =>
                {
                    RoleProperties.Position = GUILD_ROLE_POSITION;
                });

                errorhint = "Failed to create Guild Channel!";
                SocketCategoryChannel guildCategory = guild.GetChannel(GuildChannelHelper.GuildCategoryId) as SocketCategoryChannel;
                if (guildCategory == null)
                {
                    throw new Exception("Could not find Guild Category Channel!");
                }
                RestTextChannel guildChannel = await guild.CreateTextChannelAsync(name, TextChannelProperties =>
                {
                    TextChannelProperties.CategoryId = GuildChannelHelper.GuildCategoryId;
                    TextChannelProperties.Topic      = "Private Guild Channel for " + name;
                });

                errorhint = "Failed to copy guildcategories permissions";
                foreach (Overwrite overwrite in guildCategory.PermissionOverwrites)
                {
                    IRole role = guild.GetRole(overwrite.TargetId);
                    if (role != null)
                    {
                        await guildChannel.AddPermissionOverwriteAsync(role, overwrite.Permissions);
                    }
                }
                errorhint = "Failed to set Guild Channel Permissions!";
                await guildChannel.AddPermissionOverwriteAsync(guildRole, GuildRoleChannelPerms);

                await guildChannel.AddPermissionOverwriteAsync(captain, CaptainChannelPerms);

                errorhint = "Failed to add Guild Role to Captain!";
                await captain.AddRoleAsync(guildRole);

                errorhint = "Failed to add GuildCaptain Role to Captain!";
                SocketRole captainRole = guild.GetRole(SettingsModel.GuildCaptainRole);
                if (captainRole != null)
                {
                    await captain.AddRoleAsync(captainRole);
                }
                errorhint = "Failed to add Guild Role to a Member!";
                foreach (SocketGuildUser member in members)
                {
                    await member.AddRoleAsync(guildRole);
                }
                errorhint = "Failed to create MinecraftGuild!";

                StringBuilder memberPingString = new StringBuilder();

                MinecraftGuild minecraftGuild = new MinecraftGuild(guildChannel.Id, guildRole.Id, color, name, captain.Id);
                for (int i = 0; i < members.Count; i++)
                {
                    SocketGuildUser member = members[i];
                    minecraftGuild.MemberIds.Add(member.Id);
                    memberPingString.Append(member.Mention);
                    if (i < members.Count - 1)
                    {
                        memberPingString.Append(", ");
                    }
                }
                guilds.Add(minecraftGuild);
                errorhint = "Failed to save MinecraftGuild!";
                await SaveAll();

                errorhint = "Failed to send or pin guild info embed";
                var infomessage = await guildChannel.SendMessageAsync(embed : GuildHelpEmbed.Build());

                await infomessage.PinAsync();

                errorhint = "Notify Admins";
                await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Create ingame represantation for guild \"{name}\"", $"Name: `{name}`, Color: `{color}` (`0x{((uint)color).ToString("X")}`)\nCaptain: {captain.Mention}\nMembers: {memberPingString}");

                return(true);
            }
            catch (Exception e)
            {
                await GuildChannelHelper.SendExceptionNotification(e, $"Error creating guild {name}. Hint: {errorhint}");

                return(false);
            }
        }
Example #9
0
        public void Save()
        {
            if (_filestream == null)
            {
                return;
            }


            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("window"));

            xml.Root.Add(new XElement("location"));
            xml.Root.Element("location").Add(new XElement("x", Location.X.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Element("location").Add(new XElement("y", Location.Y.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("language", Language));
            xml.Root.Add(new XElement("ui_language", UILanguage));
            xml.Root.Add(new XElement("opacity"));
            xml.Root.Element("opacity").Add(new XElement("mainWindow", MainWindowOpacity * 100));
            xml.Root.Element("opacity").Add(new XElement("skillWindow", SkillWindowOpacity * 100));
            xml.Root.Add(new XElement("autoupdate", AutoUpdate));
            xml.Root.Add(new XElement("remember_position", RememberPosition));
            xml.Root.Add(new XElement("winpcap", Winpcap));
            xml.Root.Add(new XElement("invisible_ui_when_no_stats", InvisibleUi));
            xml.Root.Add(new XElement("allow_transparency", AllowTransparency));
            xml.Root.Add(new XElement("topmost", Topmost));
            xml.Root.Add(new XElement("debug", Debug));
            xml.Root.Add(new XElement("excel", Excel));
            xml.Root.Add(new XElement("date_in_excel_path", DateInExcelPath));
            xml.Root.Add(new XElement("excel_save_directory", ExcelSaveDirectory));
            xml.Root.Add(new XElement("excel_cma_dps_seconds", ExcelCMADPSSeconds));
            xml.Root.Add(new XElement("always_visible", AlwaysVisible));
            xml.Root.Add(new XElement("scale", Scale.ToString(CultureInfo.InvariantCulture)));
            xml.Root.Add(new XElement("lf_delay", LFDelay));
            xml.Root.Add(new XElement("partyonly", PartyOnly));
            xml.Root.Add(new XElement("showhealcrit", ShowHealCrit));
            xml.Root.Add(new XElement("detect_bosses_only_by_hp_bar", DetectBosses));
            xml.Root.Add(new XElement("only_bosses", OnlyBoss));
            xml.Root.Add(new XElement("low_priority", LowPriority));
            xml.Root.Add(new XElement("number_of_players_displayed", NumberOfPlayersDisplayed));
            xml.Root.Add(new XElement("remove_tera_alt_enter_hotkey", RemoveTeraAltEnterHotkey));
            xml.Root.Add(new XElement("enable_chat_and_notifications", EnableChat));
            xml.Root.Add(new XElement("mute_sound", MuteSound));
            xml.Root.Add(new XElement("copy_inspect", CopyInspect));
            xml.Root.Add(new XElement("format_paste_string", FormatPasteString));
            xml.Root.Add(new XElement("say_color", SayColor.ToString()));
            xml.Root.Add(new XElement("alliance_color", AllianceColor.ToString()));
            xml.Root.Add(new XElement("area_color", AreaColor.ToString()));
            xml.Root.Add(new XElement("guild_color", GuildColor.ToString()));
            xml.Root.Add(new XElement("whisper_color", WhisperColor.ToString()));
            xml.Root.Add(new XElement("general_color", GeneralColor.ToString()));
            xml.Root.Add(new XElement("group_color", GroupColor.ToString()));
            xml.Root.Add(new XElement("trading_color", TradingColor.ToString()));
            xml.Root.Add(new XElement("emotes_color", EmotesColor.ToString()));
            xml.Root.Add(new XElement("private_channel_color", PrivateChannelColor.ToString()));
            xml.Root.Add(new XElement("disable_party_event", DisablePartyEvent));
            xml.Root.Add(new XElement("show_afk_events_ingame", ShowAfkEventsIngame));

            xml.Root.Add(new XElement("teradps.io"));
            xml.Root.Element("teradps.io").Add(new XElement("user", TeraDpsUser));
            xml.Root.Element("teradps.io").Add(new XElement("token", TeraDpsToken));
            xml.Root.Element("teradps.io").Add(new XElement("enabled", SiteExport));
            xml.Root.Element("teradps.io").Add(new XElement("private_servers", new XAttribute("enabled", PrivateServerExport)));
            PrivateDpsServers.ForEach(x =>
                                      xml.Root.Element("teradps.io").Element("private_servers").Add(new XElement("server", x))
                                      );



            xml.Root.Add(new XElement("discord"));
            xml.Root.Element("discord").Add(new XElement("login", DiscordLogin));
            xml.Root.Element("discord").Add(new XElement("password", DiscordPassword));
            xml.Root.Element("discord").Add(new XElement("guilds"));
            foreach (var discordData in DiscordInfoByGuild)
            {
                var name = discordData.Key.ToString().ToLowerInvariant();
                xml.Root.Element("discord").Element("guilds").Add(new XElement(name));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("guild_infos_channel", discordData.Value.DiscordChannelGuildInfo));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("guild_quests_channel", discordData.Value.DiscordChannelGuildQuest));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("server", discordData.Value.DiscordServer));

                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("guild_infos_text", discordData.Value.GuildInfosText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("quest_infos_text", discordData.Value.QuestInfoText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("quest_list_infos_text", discordData.Value.QuestListInfoText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("quest_list_infos_header_text", discordData.Value.QuestListHeaderText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("reward_footer_text", discordData.Value.RewardFooterText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("reward_content_text", discordData.Value.RewardContentText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("reward_header_text", discordData.Value.RewardHeaderText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("target_header_text", discordData.Value.TargetHeaderText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("target_content_text", discordData.Value.TargetContentText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("target_footer_text", discordData.Value.TargetFooterText));
                xml.Root.Element("discord").Element("guilds").Element(name).Add(new XElement("no_active_quest_text", discordData.Value.QuestNoActiveText));
            }


            _filestream.SetLength(0);
            using (var sw = new StreamWriter(_filestream, new UTF8Encoding(true)))
            {
                sw.Write(xml.Declaration + Environment.NewLine + xml);
            }
            _filestream.Close();
        }