コード例 #1
0
ファイル: TimeoutCmd.cs プロジェクト: Faded/TwitchBot
        public async Task <DateTime> AddTimeout(string recipient, int broadcasterId, double seconds, string twitchBotApiLink)
        {
            DateTime timeoutExpiration = DateTime.UtcNow.AddSeconds(seconds);

            UserBotTimeout timedoutUser = new UserBotTimeout();

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

                TimedoutUsers.RemoveAll(t => t.Username == recipient);
            }
            else
            {
                timedoutUser = await ApiBotRequest.PostExecuteTaskAsync(
                    twitchBotApiLink + $"userbottimeouts/create",
                    new UserBotTimeout { Username = recipient, Timeout = timeoutExpiration, Broadcaster = broadcasterId }
                    );
            }

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

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

            await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"broadcasters/create", freshBroadcaster);
        }
コード例 #3
0
        public async Task <string> AddModerator(string recipient, int broadcasterId, string twitchBotApiLink)
        {
            Moderators freshModerator = new Moderators {
                Username = recipient, Broadcaster = broadcasterId
            };

            Moderators addedModerator = await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"moderators/create", freshModerator);

            string name = addedModerator.Username;

            Moderators.Add(name);
            return(name);
        }
コード例 #4
0
ファイル: ErrorHandler.cs プロジェクト: maxxrafen/TwitchBot
        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.GetExecuteTaskAsync <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.PostExecuteTaskAsync(_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);
            }
        }
コード例 #5
0
        public async Task AddCustomCommand(string twitchBotApiLink, CustomCommand customCommand)
        {
            await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"customcommands/create", customCommand);

            _customCommands.Add(customCommand);
        }
コード例 #6
0
        public async Task AddModerator(string twitchBotApiLink, BotModerator botModerator)
        {
            await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"botmoderators/create", botModerator);

            _botModerators.Add(botModerator);
        }