Esempio n. 1
0
        //TODO: Add custom commands for user after (30karma ?/limited to 3 ?)

        public UserService(DiscordSocketClient client, DatabaseService databaseService, ILoggingService loggingService, UpdateService updateService,
                           Settings.Deserialized.Settings settings, UserSettings userSettings)
        {
            _client                 = client;
            rand                    = new Random();
            _databaseService        = databaseService;
            _loggingService         = loggingService;
            _updateService          = updateService;
            _settings               = settings;
            _userSettings           = userSettings;
            _mutedUsers             = new Dictionary <ulong, DateTime>();
            _xpCooldown             = new Dictionary <ulong, DateTime>();
            _canEditThanks          = new HashSet <ulong>(32);
            _thanksCooldown         = new Dictionary <ulong, DateTime>();
            _thanksReminderCooldown = new Dictionary <ulong, DateTime>();
            _codeReminderCooldown   = new Dictionary <ulong, DateTime>();

            _noXpChannels = new List <ulong>
            {
                _settings.BotCommandsChannel.Id, _settings.CasinoChannel.Id, _settings.MusicCommandsChannel.Id
            };

            /*
             * Init XP
             */
            _xpMinPerMessage = _userSettings.XpMinPerMessage;
            _xpMaxPerMessage = _userSettings.XpMaxPerMessage;
            _xpMinCooldown   = _userSettings.XpMinCooldown;
            _xpMaxCooldown   = _userSettings.XpMaxCooldown;

            /*
             * Init thanks
             */
            StringBuilder sbThanks = new StringBuilder();
            var           thx      = _userSettings.Thanks;

            sbThanks.Append("(?i)\\b(");
            foreach (var t in thx)
            {
                sbThanks.Append(t).Append("|");
            }

            sbThanks.Length--; //Efficiently remove the final pipe that gets added in final loop, simplifying loop
            sbThanks.Append(")\\b");
            _thanksRegex                = sbThanks.ToString();
            _thanksCooldownTime         = _userSettings.ThanksCooldown;
            _thanksReminderCooldownTime = _userSettings.ThanksReminderCooldown;
            _thanksMinJoinTime          = _userSettings.ThanksMinJoinTime;

            /*
             * Init Code analysis
             */
            _codeReminderCooldownTime = _userSettings.CodeReminderCooldown;
            _codeFormattingExample    = (
                @"\`\`\`cs" + Environment.NewLine +
                "Write your code on new line here." + Environment.NewLine +
                @"\`\`\`" + Environment.NewLine);
            _codeReminderFormattingExample = (
                _codeFormattingExample + Environment.NewLine +
                "Simple as that! If you'd like me to stop reminding you about this, simply type \"!disablecodetips\"");

            LoadData();
            UpdateLoop();
        }
Esempio n. 2
0
        //TODO: Add custom commands for user after (30karma ?/limited to 3 ?)

        public UserService(DatabaseService databaseService, LoggingService loggingService, UpdateService updateService,
                           Settings.Deserialized.Settings settings, UserSettings userSettings)
        {
            rand                    = new Random();
            _databaseService        = databaseService;
            _loggingService         = loggingService;
            _updateService          = updateService;
            _settings               = settings;
            _userSettings           = userSettings;
            _mutedUsers             = new Dictionary <ulong, DateTime>();
            _xpCooldown             = new Dictionary <ulong, DateTime>();
            _canEditThanks          = new HashSet <ulong>(32);
            _thanksCooldown         = new Dictionary <ulong, DateTime>();
            _thanksReminderCooldown = new Dictionary <ulong, DateTime>();
            _codeReminderCooldown   = new Dictionary <ulong, DateTime>();

            _noXpChannels = new List <ulong>
            {
                _settings.BotCommandsChannel.Id, _settings.CasinoChannel.Id, _settings.MusicCommandsChannel.Id
            };

            /*
             * Init font for the profile card
             */
            _fontCollection = new FontCollection();

            /*_defaultFont = _fontCollection
             *  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) +
             *           "/fonts/OpenSans-Regular.ttf")
             *  .CreateFont(16);*/
            _nameFont = _fontCollection
                        .Install($"{_settings.ServerRootPath}/fonts/Consolas.ttf")
                        .CreateFont(22);
            _xpFont = _fontCollection
                      .Install($"{_settings.ServerRootPath}/fonts/Consolas.ttf")
                      .CreateFont(12);
            _ranksFont = _fontCollection
                         .Install($"{_settings.ServerRootPath}/fonts/Consolas.ttf")
                         .CreateFont(16);
            _levelTextFont = _fontCollection
                             .Install($"{_settings.ServerRootPath}/fonts/ConsolasBold.ttf")
                             .CreateFont(22);
            _levelNumberFont = _fontCollection
                               .Install($"{_settings.ServerRootPath}/fonts/ConsolasBold.ttf")
                               .CreateFont(30);

            _subtitlesWhiteFont = _fontCollection
                                  .Install($"{_settings.ServerRootPath}/fonts/OpenSansEmoji.ttf")
                                  .CreateFont(75);

            /*
             * Init XP
             */
            _xpMinPerMessage = _userSettings.XpMinPerMessage;
            _xpMaxPerMessage = _userSettings.XpMaxPerMessage;
            _xpMinCooldown   = _userSettings.XpMinCooldown;
            _xpMaxCooldown   = _userSettings.XpMaxCooldown;

            /*
             * Init thanks
             */
            StringBuilder sbThanks = new StringBuilder();
            var           thx      = _userSettings.Thanks;

            sbThanks.Append("(?i)\\b(");
            foreach (var t in thx)
            {
                sbThanks.Append(t).Append("|");
            }

            sbThanks.Length--; //Efficiently remove the final pipe that gets added in final loop, simplifying loop
            sbThanks.Append(")\\b");
            _thanksRegex                = sbThanks.ToString();
            _thanksCooldownTime         = _userSettings.ThanksCooldown;
            _thanksReminderCooldownTime = _userSettings.ThanksReminderCooldown;
            _thanksMinJoinTime          = _userSettings.ThanksMinJoinTime;

            /*
             * Init Code analysis
             */
            _codeReminderCooldownTime = _userSettings.CodeReminderCooldown;
            _codeFormattingExample    = (
                @"\`\`\`cs" + Environment.NewLine +
                "Write your code on new line here." + Environment.NewLine +
                @"\`\`\`" + Environment.NewLine);
            _codeReminderFormattingExample = (
                _codeFormattingExample + Environment.NewLine +
                "Simple as that! If you'd like me to stop reminding you about this, simply type \"!disablecodetips\"");

            LoadData();
            UpdateLoop();
        }
Esempio n. 3
0
        //TODO: Add custom commands for user after (30karma ?/limited to 3 ?)

        public UserService(DatabaseService databaseService, LoggingService loggingService, UpdateService updateService)
        {
            rand                    = new Random();
            _databaseService        = databaseService;
            _loggingService         = loggingService;
            _updateService          = updateService;
            _mutedUsers             = new Dictionary <ulong, DateTime>();
            _xpCooldown             = new Dictionary <ulong, DateTime>();
            _canEditThanks          = new HashSet <ulong>(32);
            _thanksCooldown         = new Dictionary <ulong, DateTime>();
            _thanksReminderCooldown = new Dictionary <ulong, DateTime>();
            _codeReminderCooldown   = new Dictionary <ulong, DateTime>();

            _noXpChannels = new List <ulong>
            {
                Settings.GetBotCommandsChannel(),
                    Settings.GetCasinoChannel(),
                    Settings.GetMusicCommandsChannel()
            };

            /*
             * Init font for the profile card
             */
            _fontCollection = new FontCollection();

            /*_defaultFont = _fontCollection
             *  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) +
             *           "/fonts/OpenSans-Regular.ttf")
             *  .CreateFont(16);*/
            _nameFont = _fontCollection
                        .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/Consolas.ttf")
                        .CreateFont(24);
            _xpFont = _fontCollection
                      .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/Consolas.ttf")
                      .CreateFont(12);
            _ranksFont = _fontCollection
                         .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/Consolas.ttf")
                         .CreateFont(16);
            _levelTextFont = _fontCollection
                             .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/ConsolasBold.ttf")
                             .CreateFont(22);
            _levelNumberFont = _fontCollection
                               .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/ConsolasBold.ttf")
                               .CreateFont(30);

            /*_levelFont = _fontCollection
             *  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/Consolas.ttf")
             *  .CreateFont(59);*/
            /*_levelFontSmall = _fontCollection
             *  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/Consolas.ttf")
             *  .CreateFont(45);*/

            /*_subtitlesBlackFont = _fontCollection
             *  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/OpenSansEmoji.ttf")
             *  .CreateFont(80);*/
            _subtitlesWhiteFont = _fontCollection
                                  .Install(SettingsHandler.LoadValueString("serverRootPath", JsonFile.Settings) + "/fonts/OpenSansEmoji.ttf")
                                  .CreateFont(75);

            /*
             * Init XP
             */
            _xpMinPerMessage = SettingsHandler.LoadValueInt("xpMinPerMessage", JsonFile.UserSettings);
            _xpMaxPerMessage = SettingsHandler.LoadValueInt("xpMaxPerMessage", JsonFile.UserSettings);
            _xpMinCooldown   = SettingsHandler.LoadValueInt("xpMinCooldown", JsonFile.UserSettings);
            _xpMaxCooldown   = SettingsHandler.LoadValueInt("xpMaxCooldown", JsonFile.UserSettings);

            /*
             * Init thanks
             */
            StringBuilder sbThanks = new StringBuilder();

            string[] thx = SettingsHandler.LoadValueStringArray("thanks", JsonFile.UserSettings);
            sbThanks.Append("(?i)\\b(");
            for (int i = 0; i < thx.Length; i++)
            {
                sbThanks.Append(thx[i]).Append("|");
            }

            sbThanks.Length--; //Efficiently remove the final pipe that gets added in final loop, simplifying loop
            sbThanks.Append(")\\b");
            _thanksRegex                = sbThanks.ToString();
            _thanksCooldownTime         = SettingsHandler.LoadValueInt("thanksCooldown", JsonFile.UserSettings);
            _thanksReminderCooldownTime = SettingsHandler.LoadValueInt("thanksReminderCooldown", JsonFile.UserSettings);
            _thanksMinJoinTime          = SettingsHandler.LoadValueInt("thanksMinJoinTime", JsonFile.UserSettings);

            /*
             * Init Code analysis
             */
            _codeReminderCooldownTime = SettingsHandler.LoadValueInt("codeReminderCooldown", JsonFile.UserSettings);
            _codeFormattingExample    = (
                @"\`\`\`cs" + Environment.NewLine +
                "Write your code on new line here." + Environment.NewLine +
                @"\`\`\`" + Environment.NewLine);
            _codeReminderFormattingExample = (
                _codeFormattingExample + Environment.NewLine +
                "Simple as that! If you'd like me to stop reminding you about this, simply type \"!disablecodetips\"");

            LoadData();
            UpdateLoop();
        }