Beispiel #1
0
        void BackupStats(List <string> write)
        {
            DateTime now    = DateTime.Now;
            TxtFile  backup = new TxtFile($@"{backupDirectoryPath}\{now.Year}-{now.Month}-{now.Day}-UserStats.ini");

            backup.WriteAllLines(write);
        }
Beispiel #2
0
        public Commands(TwitchBot Bot, string quotePath, string commandPath = @"/home/iggnaccy/IggiBot4/IggiBot4/bin/Debug/commands.txt")
        {
            chatCommands    = new Dictionary <string, Command>();
            whisperCommands = new Dictionary <string, Command>();
            coinCheckList   = new Queue <string>();
            commandText     = new TxtFile(commandPath);
            quoteText       = new TxtFile(quotePath);
            quotes          = new Dictionary <int, string>();
            bot             = Bot;
            LoadCommands();
            LoadQuotes();
            auctionTimer = new Timer((sender) =>
            {
                if (!auctionOpen)
                {
                    return;
                }
                auctionLeft--;
                string winner = auctionWinner;
                int winAmount = auctionBid;

                if (auctionLeft == auctionLastAnnounement)
                {
                    bot.SendMessageRaw($"The auction will end soon! Current winner is {winner} with a bid of {winAmount} {Credentials.currencyName} ! We are auctioning for {auctionInfo}");
                }
                else if (auctionLeft * 2 == auctionTime)
                {
                    bot.SendMessageRaw($"The auction is near it's half-way spot! Current winner is {winner} with a bid of {winAmount} {Credentials.currencyName} ! We are auctioning for {auctionInfo}");
                }
                else if (auctionLeft == 0)
                {
                    bot.SendMessageRaw($"@{Credentials.targetStream} The auction has closed! The winner is @{winner}, with a bid of {winAmount} {Credentials.currencyName}");
                    bot.coinSystem.AddCoins(winner, -winAmount);
                    auctionBid    = auctionTime = auctionLeft = 0;
                    auctionLast   = winner;
                    auctionWinner = auctionInfo = "";
                    auctionOpen   = false;
                }
            }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            coinCheckTimer = new Timer((sender) =>
            {
                if (coinCheckList.Count == 0)
                {
                    return;
                }
                string msg = "";
                while (coinCheckList.Count > 0 && msg.Length <= 500)
                {
                    string username = coinCheckList.Dequeue();
                    msg            += $"@{username} has {bot.coinSystem.GetCoins(username)} {Credentials.currencyName}, ";
                }
                msg = msg.Substring(0, msg.Length - 2);
                bot.SendMessageRaw(msg);
            }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(2.5));
            bot.client.OnChatCommandReceived    += ChatCommandHandler;
            bot.client.OnWhisperCommandReceived += WhisperCommandHandler;
            FillChatCommands();
            FillWhisperCommands();
        }
Beispiel #3
0
        public static void SaveCredentials(string absolutePath)
        {
            TxtFile       file  = new TxtFile(absolutePath);
            List <string> write = new List <string>
            {
                $"Destination:{targetStream}",
                $"BotUsername:{botUsername}",
                $"BotToken:{botToken}",
                $"BotRefreshToken:{botRefreshToken}",
                $"AuthToken:{authToken}",
                $"AuthRefreshToken:{authRefreshToken}",
                $"ClientId:{clientId}",
                $"CurrencyName:{currencyName}"
            };

            file.WriteAllLines(write);
        }
 public PersonalizedCommands(TwitchBot Bot, string krakenPath, string extraCoinsPath, string donationPath, string dndPath)
 {
     bot = Bot;
     bot.client.OnGiftedSubscription += GiftSub;
     bot.client.OnNewSubscriber      += NewSub;
     bot.client.OnReSubscriber       += Resub;
     //bot.client.OnAnonGiftedSubscription += AnonGiftSub;
     bot.client.OnChatCommandReceived    += OnChatCommandReceived;
     bot.client.OnWhisperCommandReceived += OnWhisperCommandReceived;
     bot.client.OnMessageReceived        += CountBits;
     customCommands = new Dictionary <string, Command>();
     krakenText     = new TxtFile(krakenPath);
     extraCoinsText = new TxtFile(extraCoinsPath);
     donationsText  = new TxtFile(donationPath);
     dndRewardsText = new TxtFile(dndPath);
     VariableInitialization();
     FillPersonalizedChatCommands();
     FillPersonalizedWhisperCommands();
 }
Beispiel #5
0
 public TwitchBot(string endUser)
 {
     closing = false;
     SetPaths(endUser);
     logFile      = new TxtFile(logPath);
     errorLogFile = new TxtFile(errorLogPath);
     Credentials.ReadCredentials(credentialsPath);
     restarts            = 0;
     lastUpdatedChatters = DateTime.Now;
     Connect();
     coinSystem           = new CoinSystem(this, userStatsPath, backupPath);
     personalizedCommands = new PersonalizedCommands(this, krakenPath, extraCoinsPath, donationsPath, dndPath);
     commands             = new Commands(this, quotePath, commandPath);
     onlineCheck          = new Timer(async(x) =>
     {
         if ((await GetUptime()).HasValue)
         {
             if (!online)
             {
                 personalizedCommands.NewSession();
             }
             else
             {
                 await personalizedCommands.UpdateFiles();
             }
             online = true;
         }
         else
         {
             if (online)
             {
                 personalizedCommands.EndSession();
                 coinSystem.SaveStats();
             }
             online = false;
         }
     }, null, TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(5));
 }
Beispiel #6
0
        public CoinSystem(TwitchBot Bot, string userStatsPath, string backupDirectoryPath)
        {
            userStats    = new Dictionary <string, UserStats>();
            userStatsTxt = new TxtFile(userStatsPath);
            LoadStats();
            this.backupDirectoryPath = backupDirectoryPath;
            bot          = Bot;
            cache        = new SubscriberCache(bot);
            passiveCoins = new Timer(async(sender) =>
            {
                if (bot.online == false)
                {
                    return;
                }
                var list = await bot.GetChatList();
                if (list != null && list.Count > 0)
                {
                    foreach (var u in list)
                    {
                        int subTier = await cache.GetOrCreate(u.Username);
                        switch (subTier)
                        {
                        case 0:
                            AddCoins(u.Username, 1);
                            break;

                        case 1:
                            AddCoins(u.Username, 2);
                            break;

                        case 2:
                            AddCoins(u.Username, 3);
                            break;

                        case 3:
                            AddCoins(u.Username, 6);
                            break;
                        }
                    }
                    if (saveCounter >= 5)
                    {
                        SaveStats();
                        saveCounter = 0;
                    }
                    saveCounter++;
                }
            }, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));

            /*chatTime = new Timer(async (sender) =>
             * {
             *  if (bot.online == false) return;
             *  var list = await bot.GetChatList();
             *  if (list != null)
             *  {
             *      foreach (var u in list)
             *      {
             *          AddTime(u.Username, 1);
             *      }
             *  }
             * },null,TimeSpan.FromMinutes(1),TimeSpan.FromMinutes(1));
             */
        }
Beispiel #7
0
        //Read credentials from file
        public static void ReadCredentials(string absolutePath)
        {
            TxtFile file  = new TxtFile(absolutePath);
            var     lines = file.ReadAllLines();

            for (int i = 0; i < lines.Count; i++)
            {
                var split = lines[i].Split(new[] { ':' });
                switch (split[0].ToLower())
                {
                case "botname":
                case "botusername":
                {
                    botUsername = split[1];
                }
                break;

                case "bottoken":
                {
                    botToken = split[1];
                }
                break;

                case "destination":
                {
                    targetStream = split[1];
                }
                break;

                case "clientid":
                {
                    clientId = split[1];
                }
                break;

                case "authtoken":
                case "authenticationtoken":
                {
                    authToken = split[1];
                }
                break;

                case "currencyname":
                {
                    currencyName = split[1];
                }
                break;

                case "botrefreshtoken":
                {
                    botRefreshToken = split[1];
                }
                break;

                case "authrefreshtoken":
                {
                    authRefreshToken = split[1];
                }
                break;

                default:
                    break;
                }
            }
        }