public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            ircClient.Channels.AddIfNotExist(channelName);

            if (ircClient.Channels[channelName].Users.Any(u => u.Nick.Equals(nickName))) return;

            logger.Write($"Detected new user by PRIVMSG {nickName} on channel {channelName}");
            var user = ircClient.UserService.GetOrCreateUser(nickName, channelName);
            ircClient.Channels[channelName].AddUser(user);
        }
示例#2
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            WPFChatter WPFChatter = new WPFChatter();

            Brush NickColor = WPFChatter.getColor(nickName);

            DotDotBot.GUI.MainWindow._mainWindow.tbChatOutput.Inlines.Add(new Run(nickName) { Foreground = NickColor, FontStyle = FontStyles.Italic});
            DotDotBot.GUI.MainWindow._mainWindow.tbChatOutput.Inlines.Add($": {message.Trailing}\n");
            DotDotBot.GUI.MainWindow._mainWindow.tbChatOutput.Inlines.Add(new Run("1\n") { FontSize = 4, Foreground = Brushes.Transparent});
        }
示例#3
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            if (MessageHelper.IsMessageFromMe(message, ircClient.Credentials))
            {
                logger.Write($"We left channel {channelName}");
                ircClient.Channels.RemoveIfExists(channelName);
            }
            else
            {
                logger.Write($"PART {nickName} from channel {channelName}");
                var user = ircClient.UserService.GetOrCreateUser(nickName, channelName);
                ircClient.Channels[channelName].RemoveUser(user);
            }
        }
示例#4
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            if (_activeCountdownChannels.Any(c => c.ChannelName.Equals(channelName))) return; //We are already doing a countdown on this channel

            if (!_config.EnabledForChannels.Contains(channelName.ToLower())) return; //Check if we have this plugin enabled for this channel

            if (!message.Trailing.ToLower().TrimStart().Equals("!cd")) return; //This is the text that will trigger this command

            if (!ircClient.Channels[channelName].Users.Any(u => u.Nick.Equals(nickName) && u.AccessLevel >= _config.MinimumAccessLevel))
            {
                return; //User need an access level greater than 0 to access this command
            }

            _activeCountdownChannels.Add(new CountDownChannel(channelName, 5, ircClient));
        }
示例#5
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            _logger = logger;
            _ircClient = ircClient;

            var userCommand = message.Trailing.Split(' ')[0].ToLower().TrimStart();
            var nickName = message.GetSender();
            var channelName = message.GetChannelName();

            if (CommandHelper.IsChannelCommandOnCooldown(userCommand, channelName)) return;

            switch (userCommand)
            {
                case "!insult":
                    DoInsult(nickName, channelName);
                    CommandHelper.CooldownChannelCommand(userCommand, channelName, 120);
                    break;
            }
        }
示例#6
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            ircClient.Channels.AddIfNotExist(channelName);

            if (MessageHelper.IsMessageFromMe(message, ircClient.Credentials))
            {
                logger.Write($"We joined channel {channelName}");
                ircClient.TwitchService.AddToStreamWatchList(channelName);

                var viewers = TwitchApiClient.GetChatters(channelName.Substring(1));
                logger.Write($"Got {viewers.Count} viewers from API. Loading them now:");

                foreach (var viewer in viewers)
                {
                    logger.WriteIndented($"API: {viewer} on channel {channelName}");
                    var user = ircClient.UserService.GetOrCreateUser(viewer, channelName);
                    ircClient.Channels[channelName].AddUser(user);
                }

                var moderators = TwitchApiClient.GetOnlieModerators(channelName.Substring(1));
                logger.Write($"Got {moderators.Count} moderators from API. Loading them now:");

                foreach (var moderator in moderators)
                {
                    logger.WriteIndented($"API: {moderator} (mod) on channel {channelName}");
                    var user = ircClient.UserService.GetOrCreateUser(moderator, channelName);
                    user.IsModerator = true;
                    ircClient.Channels[channelName].AddUser(user);
                }

                logger.Write("Done loading users found through API.");
            }
            else
            {
                //Load any data we have on this client from the database, then add it to our internal list of users
                logger.Write($"JOIN {nickName} on channel {channelName}");
                var user = ircClient.UserService.GetOrCreateUser(nickName, channelName);
                ircClient.Channels[channelName].AddUser(user);
            }
        }
示例#7
0
        private void DoSetAccess(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var nickName = message.GetSender();
            var channelName = message.GetChannelName();

            var userAccessLevel = ircClient.UserService.GetOrCreateUser(nickName, channelName).AccessLevel;

            if (userAccessLevel <= 0) return;

            try
            {
                var targetNickName = message.Trailing.Split(' ')[1];
                var targetAccessLevel = int.Parse(message.Trailing.Split(' ')[2]);

                if (targetAccessLevel > (userAccessLevel))
                {
                    logger.Write(
                        $"Not enough access for {nickName} to use !setaccess on {channelName} useraccesslevel={userAccessLevel} target={targetAccessLevel}");
                    ircClient.SendMessage(
                        $"You cannot set another users access level to a number greater than your own ({userAccessLevel})",
                        channelName);
                    return;
                }

                var targetUser = ircClient.UserService.GetOrCreateUser(targetNickName, channelName);
                targetUser.AccessLevel = targetAccessLevel;
                ircClient.UserService.SaveUser(targetUser);

                ircClient.SendMessage($"New access level for @{targetNickName} is {targetAccessLevel}.", channelName);
            }
            catch (Exception e)
            {
                if (e is FormatException || e is IndexOutOfRangeException)
                {
                    ircClient.SendMessage($"Usage: !setaccess <user> <accesslevel>", channelName);
                    return;
                }

                throw;
            }
        }
示例#8
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            try
            {
                var nickName = message.GetSender();
                var channelName = message.GetChannelName();
                var userCommand = message.Trailing.Split(' ')[0].ToLower().TrimStart();

                if (IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;

                switch (userCommand)
                {
                    case "!setaccess":
                        DoSetAccess(message, ircClient, logger);
                        break;
                }
            }
            catch (Exception e)
            {
                //Todo: make this better. Should not catch everything
                logger.Write(e.Message);
            }
        }
示例#9
0
        private void DoAddBonusAll(ServerMessage message, ChannelConfiguration channelInfo)
        {
            var channelName = message.GetChannelName();

            if (!_config.Channels.Any(c => c.ChannelName.Equals(channelName))) return;

            try
            {
                var amount = int.Parse(message.Trailing.Split(' ')[1]);
                foreach (var user in _ircClient.Channels[channelName].Users)
                {
                    var currencyInfo = GetCurrencyInfo(user.Nick, channelName);
                    currencyInfo.TotalCurrency += amount;
                    _database.Update(currencyInfo);
                }

                _ircClient.SendMessage($"Everyone that is online now was given a bonus of {amount} bonus {channelInfo.CurrencyName}!", channelName);
                _logger.Write($"{message.GetSender()} did !bonusall with amount {amount} on {channelName}");
            }
            catch (Exception e)
            {
                if (e is FormatException || e is IndexOutOfRangeException)
                {
                    _ircClient.SendMessage($"Usage: !bonusall <amount>", channelName);
                    return;
                }

                throw;
            }
        }
示例#10
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            if (message.Command.Equals("376") && !_isInitialized) //We use this to initialize the plugin. This should only happen once.
            {
                _ircClient = ircClient;
                _logger = logger;

                //Subscribe to when the stream startes/ends events
                _ircClient.TwitchService.OnStreamOnline += TwitchService_OnStreamOnline;
                _ircClient.TwitchService.OnStreamOffline += TwitchService_OnStreamOffline;

                foreach (var channel in _config.Channels)
                    ircClient.TwitchService.AddToStreamWatchList(channel.ChannelName);

                foreach (var ignoredUser in _config.IgnoredUsersList)
                {
                    logger.Write($"Ignoring {ignoredUser.NickName} on {ignoredUser.ChannelName} for currency gains.");
                }

                var timer = new Timer
                {
                    AutoReset = true,
                    Interval = 60000
                };
                timer.Elapsed += _timer_Elapsed;
                timer.Enabled = true;

                _isInitialized = true;
                _logger.Write($"{GetType().Name} Initialized.");
            }
            else if (message.Command.Equals("PRIVMSG") &&
                        _isInitialized &&
                        _config.Channels.Any(c => c.ChannelName.Equals(message.GetChannelName())))
            {
                var userCommand = message.Trailing.Split(' ')[0].ToLower().TrimStart();
                var nickName = message.GetSender();
                var channelName = message.GetChannelName();

                var channelInfo = _config.Channels.FirstOrDefault(c => c.ChannelName.Equals(message.GetChannelName()));

                if (CommandHelper.IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;

                if (userCommand.Equals($"!{channelInfo.CurrencyShortName}"))
                {
                    DisplayPoints(nickName, channelName, channelInfo);
                    CommandHelper.CooldownUserCommand(userCommand, nickName, channelName, 60);
                }

                switch (userCommand)
                {
                    case "!gamble":
                        DoGamble(message, channelInfo);
                        CommandHelper.CooldownUserCommand(userCommand, nickName, channelName, 60);
                        break;

                    case "!bonus":
                        if (ircClient.UserService.GetOrCreateUser(nickName, channelName).AccessLevel < channelInfo.RequiredAccessLevelForBonus) return;
                        DoAddBonus(message, channelInfo);
                        break;

                    case "!bonusall":
                        if (ircClient.UserService.GetOrCreateUser(nickName, channelName).AccessLevel < channelInfo.RequiredAccessLevelForBonus) return;
                        DoAddBonusAll(message, channelInfo);
                        break;

                    case "!give":
                        DoGive(message, channelInfo);
                        CommandHelper.CooldownUserCommand(userCommand, nickName, channelName, 60);
                        break;
                }
            }
        }
示例#11
0
        private void DoGive(ServerMessage message, ChannelConfiguration channelInfo)
        {
            var nickName = message.GetSender();
            var channelName = message.GetChannelName();

            if (!_config.Channels.Any(c => c.ChannelName.Equals(channelName))) return;

            try
            {
                var target = message.Trailing.Split(' ')[1];
                var amount = int.Parse(message.Trailing.Split(' ')[2]);
                var currencySenderInfo = GetCurrencyInfo(nickName, channelName);
                var currencyTargetInfo = GetCurrencyInfo(target, channelName);

                if (currencySenderInfo.CanAfford(amount))
                {
                    currencySenderInfo.UsedCurrency += amount;
                    _database.Update(currencySenderInfo);

                    currencyTargetInfo.TotalCurrency += amount;
                    _database.Update(currencyTargetInfo);

                    _ircClient.SendMessage($"@{nickName} gave @{target} {amount} {channelInfo.CurrencyName}! How kind :)", channelName);
                    _logger.Write($"{message.GetSender()} did !give to {target} with amount {amount} on {channelName}");
                }
                else
                {
                    _ircClient.SendMessage($"Sorry @{nickName}, but you cannot afford to give {amount} {channelInfo.CurrencyName}. You only have {channelInfo.CurrencyName} {channelInfo.CurrencyName} in the bank.", channelName);
                }
            }
            catch (Exception e)
            {
                if (e is FormatException || e is IndexOutOfRangeException)
                {
                    _ircClient.SendMessage($"Usage: !give <user> <amount>", channelName);
                    return;
                }

                throw;
            }
        }
示例#12
0
        private void DoGamble(ServerMessage message, ChannelConfiguration channelInfo)
        {
            var nickName = message.GetSender();
            var channelName = message.GetChannelName();

            if (!_config.Channels.Any(c => c.ChannelName.Equals(channelName))) return;

            var currencyInfo = GetCurrencyInfo(nickName, channelName);

            if (currencyInfo == null) return; //Perhaps notify the user?

            try
            {
                var amount = 0;
                if (int.TryParse(message.Trailing.Split(' ')[1], out amount))
                {
                    if (!currencyInfo.CanAfford(amount))
                    {
                        _ircClient.SendMessage($"Sorry @{nickName}, but you don't have that many {channelInfo.CurrencyName}... You have {currencyInfo.AvailableAmount} {channelInfo.CurrencyName} to spend.", channelName);
                        return;
                    }

                    var randomNumber = _random.Next(1, 101); //Note: maxValue in random is NOT included in the range

                    if (randomNumber <= 50)
                    {
                        currencyInfo.UsedCurrency += amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and lost {amount} and now has {currencyInfo.AvailableAmount} {channelInfo.CurrencyName}. Better luck next time!", channelName);
                        _database.Update(currencyInfo);
                    }
                    else if (randomNumber <= 98)
                    {
                        //You won and doubled!
                        currencyInfo.TotalCurrency += amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and DOUBLED the bet! You won {amount} and now has {currencyInfo.AvailableAmount} {channelInfo.CurrencyName}!", channelName);
                        _database.Update(currencyInfo);
                    }
                    else //(randomNumber > 98)
                    {
                        //You won and trippled the points!
                        currencyInfo.TotalCurrency += 2 * amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and TRIPPLED the bet! You won {2 * amount} and now has {currencyInfo.AvailableAmount} {channelInfo.CurrencyName}!", channelName);
                        _database.Update(currencyInfo);
                    }
                }
            }
            catch (Exception e)
            {
                if (e is FormatException || e is IndexOutOfRangeException)
                {
                    _ircClient.SendMessage($"Usage: !gamble <amount>. Roll a number between 1 and 100. Lose: 1-50, Double: 51-98, Tripple: 99-100", message.GetChannelName());
                    return;
                }

                throw;
            }
        }
示例#13
0
        private void DoAddBonus(ServerMessage message)
        {
            var channelName = message.GetChannelName();

            if (!_watchedChannelsList.Contains(channelName)) return;
            if (!_ircClient.Channels[channelName].GetUser(message.GetSender()).IsModerator) return;

            try
            {
                var target = message.Trailing.Split(' ')[1];
                var amount = int.Parse(message.Trailing.Split(' ')[2]);
                var currencyInfo = GetCurrencyInfo(target, channelName);

                currencyInfo.TotalCurrency += amount;
                _database.Update(currencyInfo);

                _ircClient.SendMessage($"{target} was given a bonus of {amount} and now have {currencyInfo.TotalCurrency - currencyInfo.UsedCurrency} points.", channelName);
                _logger.Write($"{message.GetSender()} did !bonus to {target} with amount {amount} on {channelName}");
            }
            catch (Exception)
            {
                _ircClient.SendMessage($"Usage: !bonus <user> <amount>", channelName);
            }
        }
示例#14
0
        private void DoAddBonus(ServerMessage message, ChannelConfiguration channelInfo)
        {
            var channelName = message.GetChannelName();

            if (!_config.Channels.Any(c => c.ChannelName.Equals(channelName))) return;

            try
            {
                var target = message.Trailing.Split(' ')[1];
                var amount = int.Parse(message.Trailing.Split(' ')[2]);
                var currencyInfo = GetCurrencyInfo(target, channelName);

                currencyInfo.TotalCurrency += amount;
                _database.Update(currencyInfo);

                _ircClient.SendMessage($"{target} was given a bonus of {amount} and now have {currencyInfo.AvailableAmount} {channelInfo.CurrencyName}.", channelName);
                _logger.Write($"{message.GetSender()} did !bonus to {target} with amount {amount} on {channelName}");
            }
            catch (Exception e)
            {
                if (e is FormatException || e is IndexOutOfRangeException)
                {
                    _ircClient.SendMessage($"Usage: !bonus <user> <amount>", channelName);
                    return;
                }

                throw;
            }
        }
示例#15
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            if (message.Command.Equals("376") && !_isInitialized) //We use this to initialize the plugin. This should only happen once.
            {
                _ircClient = ircClient;
                _logger = logger;

                //Subscribe to when the stream startes/ends events
                _ircClient.TwitchService.OnStreamOnline += TwitchService_OnStreamOnline;
                _ircClient.TwitchService.OnStreamOffline += TwitchService_OnStreamOffline;

                _timer.AutoReset = true;
                _timer.Interval = 60000;
                _timer.Elapsed += _timer_Elapsed;
                _timer.Enabled = true;

                _dataFolder = PluginHelper.GetPluginDataFolder(this);

                _database = new SQLiteConnection(new SQLitePlatformWin32(), Path.Combine(_dataFolder, "CurrencyPlugin.db"));
                _database.CreateTable<CurrencyUserModel>();

                //This is for debugging
                //_watchedChannelsList.Add("#unseriouspid");
                //_onlineChannelsList.Add("#unseriouspid");

                _logger.Write($"{GetType().Name} Initialized.");
                _isInitialized = true;
            }
            else if (message.Command.Equals("PRIVMSG") &&
                        _isInitialized &&
                        _watchedChannelsList.Contains(message.GetChannelName()))
            {
                var userCommand = message.Trailing.Split(' ')[0].ToLower().TrimStart();
                var nickName = message.GetSender();
                var channelName = message.GetChannelName();

                switch (userCommand)
                {
                    case "!points":
                        if (IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;
                        DisplayPoints(nickName, channelName);
                        CooldownUserCommand(userCommand, nickName, channelName);
                        break;

                    case "!gamble":
                        if (IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;
                        DoGamble(message);
                        CooldownUserCommand(userCommand, nickName, channelName);
                        break;

                    case "!bonus":
                        DoAddBonus(message);
                        break;

                    case "!bonusall":
                        DoAddBonusAll(message);
                        break;
                }
            }
        }
示例#16
0
        private void DoGamble(ServerMessage message)
        {
            var nickName = message.GetSender();
            var channelName = message.GetChannelName();

            if (!_watchedChannelsList.Contains(channelName)) return;

            var currencyInfo = GetCurrencyInfo(nickName, channelName);

            if (currencyInfo == null) return; //Perhaps notify the user?

            var availableCurrency = currencyInfo.TotalCurrency - currencyInfo.UsedCurrency;

            try
            {
                var amount = 0;
                if (int.TryParse(message.Trailing.Split(' ')[1], out amount))
                {
                    if (amount > availableCurrency)
                    {
                        _ircClient.SendMessage($"Sorry @{nickName}, but you don't have that many points... You have {availableCurrency} points to spend.", channelName);
                        return;
                    }

                    var randomNumber = _random.Next(1, 101); //Note: maxValue in random is NOT included in the range

                    if (randomNumber <= 50)
                    {
                        currencyInfo.UsedCurrency += amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and lost {amount} and now have {currencyInfo.TotalCurrency - currencyInfo.UsedCurrency} points. Better luck next time!", channelName);
                        _database.Update(currencyInfo);
                    }
                    else if (randomNumber <= 98)
                    {
                        //You won and doubled!
                        currencyInfo.TotalCurrency += amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and DOUBLED the bet! You won {amount} and now have {currencyInfo.TotalCurrency - currencyInfo.UsedCurrency} points!", channelName);
                        _database.Update(currencyInfo);
                    }
                    else //(randomNumber > 98)
                    {
                        //You won and trippled the points!
                        currencyInfo.TotalCurrency += 2 * amount;
                        _ircClient.SendMessage($"@{nickName} rolled {randomNumber} and TRIPPLED the bet! You won {2 * amount}  and now have {currencyInfo.TotalCurrency - currencyInfo.UsedCurrency} points!", channelName);
                        _database.Update(currencyInfo);
                    }
                }
            }
            catch (Exception)
            {
                _ircClient.SendMessage($"Usage: !gamble <amount>. Roll a number between 1 and 100. Lose: 1-50, Double: 51-98, Tripple: 99-100", message.GetChannelName());
            }
        }
示例#17
0
        private void DoAddBonusAll(ServerMessage message)
        {
            var channelName = message.GetChannelName();

            if (!_watchedChannelsList.Contains(channelName)) return;
            if (!_ircClient.Channels[channelName].GetUser(message.GetSender()).IsModerator) return;

            try
            {
                var amount = int.Parse(message.Trailing.Split(' ')[1]);
                foreach (var user in _ircClient.Channels[channelName].Users)
                {
                    var currencyInfo = GetCurrencyInfo(user.Nick, channelName);
                    currencyInfo.TotalCurrency += amount;
                    _database.Update(currencyInfo);
                }

                _ircClient.SendMessage($"Everyone that is online now was given a bonus of {amount} bonus points!", channelName);
                _logger.Write($"{message.GetSender()} did !bonusall with amount {amount} on {channelName}");
            }
            catch (Exception)
            {
                _ircClient.SendMessage($"Usage: !bonusall <amount>", channelName);
            }
        }