Beispiel #1
0
        public async Task <DateTime> AddTimeout(string recipient, int broadcasterId, string twitchBotApiLink, double seconds = -1.0)
        {
            DateTime timeoutExpiration = seconds == -1.0
                ? timeoutExpiration = DateTime.MaxValue
                : DateTime.UtcNow.AddSeconds(seconds);

            BotTimeout timedoutUser = new BotTimeout();

            if (TimedoutUsers.Any(m => m.Username == recipient))
            {
                timedoutUser = await ApiBotRequest.PatchExecuteAsync <BotTimeout>(
                    twitchBotApiLink + $"bottimeouts/patch/{broadcasterId}?username={recipient}",
                    "timeout",
                    timeoutExpiration);

                TimedoutUsers.RemoveAll(t => t.Username == recipient);
            }
            else
            {
                timedoutUser = await ApiBotRequest.PostExecuteAsync(
                    twitchBotApiLink + $"bottimeouts/create",
                    new BotTimeout { Username = recipient, Timeout = timeoutExpiration, BroadcasterId = broadcasterId }
                    );
            }

            TimedoutUsers.Add(new TimeoutUser
            {
                Username             = recipient,
                TimeoutExpirationUtc = timeoutExpiration,
                HasBeenWarned        = false
            });

            return(timeoutExpiration);
        }
Beispiel #2
0
        public async Task AddBroadcaster(string twitchBotApiLink)
        {
            Broadcaster freshBroadcaster = new Broadcaster
            {
                Username = Username,
                TwitchId = int.Parse(TwitchId)
            };

            await ApiBotRequest.PostExecuteAsync(twitchBotApiLink + $"broadcasters/create", freshBroadcaster);
        }
        public async Task AddModerator(string twitchBotApiLink, BotModerator botModerator)
        {
            await ApiBotRequest.PostExecuteAsync(twitchBotApiLink + $"botmoderators/create", botModerator);

            _botModerators.Add(botModerator);
        }
        public async Task AddCustomCommand(string twitchBotApiLink, CustomCommand customCommand)
        {
            await ApiBotRequest.PostExecuteAsync(twitchBotApiLink + $"customcommands/create", customCommand);

            _customCommands.Add(customCommand);
        }
Beispiel #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);
            }
        }