Пример #1
0
        public async Task FindBroadcaster(string twitchId, string twitchBotApiLink, string username = "")
        {
            Broadcaster broadcaster = null;

            if (!string.IsNullOrEmpty(username))
            {
                broadcaster = await ApiBotRequest.GetExecuteAsync <Broadcaster>(twitchBotApiLink + $"broadcasters/get/{twitchId}?username={username}");
            }
            else
            {
                broadcaster = await ApiBotRequest.GetExecuteAsync <Broadcaster>(twitchBotApiLink + $"broadcasters/get/{twitchId}");
            }

            if (broadcaster != null)
            {
                Username   = broadcaster.Username;
                TwitchId   = twitchId;
                DatabaseId = broadcaster.Id;
            }
        }
Пример #2
0
 public async Task <List <BotTimeout> > GetTimeouts(int broadcasterId, string twitchBotApiLink)
 {
     return(await ApiBotRequest.GetExecuteAsync <List <BotTimeout> >(twitchBotApiLink + $"bottimeouts/get/{broadcasterId}"));
 }
Пример #3
0
 public async Task LoadExistingModerators(string twitchBotApiLink, int broadcasterId)
 {
     _botModerators = await ApiBotRequest.GetExecuteAsync <List <BotModerator> >(twitchBotApiLink + $"botmoderators/get/{broadcasterId}");
 }
Пример #4
0
 public async Task LoadCustomCommands(string twitchBotApiLink, int broadcasterId)
 {
     _customCommands = await ApiBotRequest.GetExecuteAsync <List <CustomCommand> >(twitchBotApiLink + $"customcommands/get/{broadcasterId}");
 }
Пример #5
0
        public async Task LogError(Exception ex, string className, string methodName, bool hasToExit, string botCmd = "N/A", string userMsg = "N/A")
        {
            Console.WriteLine("Error: " + ex.Message);

            try
            {
                /* If username not available, grab default user to show local error after db connection */
                if (_broadcasterId == 0)
                {
                    Broadcaster broadcaster = await ApiBotRequest.GetExecuteAsync <Broadcaster>(_botConfig.TwitchBotApiLink + $"broadcasters/get/-1");

                    _broadcasterId = broadcaster.Id;
                }

                /* Get line number from error message */
                int          lineNumber = 0;
                const string lineSearch = ":line ";
                int          index      = ex.StackTrace.LastIndexOf(lineSearch);

                if (index != -1)
                {
                    string lineNumberText = ex.StackTrace.Substring(index + lineSearch.Length);
                    if (!int.TryParse(lineNumberText, out lineNumber))
                    {
                        lineNumber = -1; // couldn't parse line number
                    }
                }

                ErrorLog error = new ErrorLog
                {
                    ErrorTime     = DateTime.UtcNow,
                    ErrorLine     = lineNumber,
                    ErrorClass    = className,
                    ErrorMethod   = methodName,
                    ErrorMsg      = ex.Message,
                    BroadcasterId = _broadcasterId,
                    Command       = botCmd,
                    UserMsg       = userMsg
                };

                await ApiBotRequest.PostExecuteAsync(_botConfig.TwitchBotApiLink + $"errorlogs/create", error);

                string publicErrMsg = "I ran into an unexpected internal error! "
                                      + "@" + _botConfig.Broadcaster + " please look into the error log when you have time";

                if (hasToExit)
                {
                    publicErrMsg += ". I am leaving as well. Have a great time with this stream everyone KonCha";
                }

                if (_irc != null)
                {
                    _irc.SendPublicChatMessage(publicErrMsg);
                }

                if (hasToExit)
                {
                    Console.WriteLine();
                    Console.WriteLine("Shutting down now...");
                    Thread.Sleep(3000);
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Logging error found: " + e.Message);
                Console.WriteLine("Please inform author of this error!");
                Thread.Sleep(5000);
            }
        }