Пример #1
0
 private void OnWhisperCommandReceived(object sender, TwitchLib.Client.Events.OnWhisperCommandReceivedArgs e)
 {
     try
     {
         if (whisperCommands.TryGetValue(e.Command.CommandText, out Command c))
         {
             c.Invoke(e).GetAwaiter().GetResult();
         }
     }
     catch (Exception ex)
     {
         bot.LogError("PCommand - WhisperCommand", $"Error occured during {e.Command.CommandText} whisper command: {ex.Message}");
     }
 }
Пример #2
0
 void FillWhisperCommands()
 {
     whisperCommands.Add("average", new Command((args) =>
     {
         if (args.isBroadcaster || args.isOwner)
         {
             int count       = 0;
             long value      = 0;
             long time       = 0;
             int minimumTime = 240;
             foreach (var u in bot.coinSystem.userStats)
             {
                 if (u.Value.time >= minimumTime)
                 {
                     count++;
                     value += u.Value.coins;
                     time  += u.Value.time;
                 }
             }
             value            /= count;
             time             /= count;
             TimeSpan timeSpan = TimeSpan.FromMinutes(time);
             bot.SendWhisper(args.Caller, $"The average user has {value} coins and spent {timeSpan.Hours}h {timeSpan.Minutes}m in chat. Stats based on {count} users");
         }
         return(Task.Run(() => { return 0; }));
     }));
     whisperCommands.Add("top", new Command(async(args) =>
     {
         int count = 10;
         if (args.Arguments.Count > 0)
         {
             if (!int.TryParse(args.Arguments[0], out count))
             {
                 count = 10;
             }
         }
         var topX = bot.coinSystem.userStats.ToList();
         topX.Sort((x, y) => { return(y.Value.coins - x.Value.coins); });
         string msg = "";
         for (int i = 0; i < count; i++)
         {
             msg += $"{topX[i].Key}: {topX[i].Value.coins}\n";
         }
         var paste = await bot.PasteOnPasteBin(msg, $"Top {count}");
         bot.SendWhisperRaw(args.Caller, paste);
         return(3);
     }));
     whisperCommands.Add("transfer", new Command((args) =>
     {
         if (args.isOwner || args.isBroadcaster)
         {
             if (args.Arguments.Count >= 2)
             {
                 if (bot.coinSystem.CheckKey(args.Arguments[0]) && bot.coinSystem.CheckKey(args.Arguments[1]))
                 {
                     bot.coinSystem.userStats[args.Arguments[1].ToLower()] += bot.coinSystem.userStats[args.Arguments[0].ToLower()];
                     bot.coinSystem.userStats.Remove(args.Arguments[0].ToLower());
                     bot.SendWhisper(args.Caller, $"Successfully moved {args.Arguments[0]}'s stats over to {args.Arguments[1]} and removed the former from the base");
                 }
                 else
                 {
                     bot.SendWhisper(args.Caller, $"One or more arguments weren't present in the database");
                 }
                 return(Task.Run(() => { return 0; }));
             }
             else
             {
                 return(Task.Run(() => { return 0; }));
             }
         }
         else
         {
             return(Task.Run(() => { return 0; }));
         }
     }));
     whisperCommands.Add("morethan", new Command((args) =>
     {
         if (args.Arguments.Count < 1)
         {
             return(Task.Run(() => { return 0; }));
         }
         if (int.TryParse(args.Arguments[0], out int x))
         {
             int result = 0;
             foreach (var l in bot.coinSystem.userStats)
             {
                 if (l.Value.coins >= x)
                 {
                     result++;
                 }
             }
             bot.SendWhisper(args.Caller, result.ToString());
             return(Task.Run(() => { return 5; }));
         }
         else
         {
             return(Task.Run(() => { return 0; }));
         }
     }));
     whisperCommands.Add("sendmsg", new Command((args) =>
     {
         if (args.isBroadcaster || args.isModerator || args.isOwner)
         {
             bot.SendMessageRaw(args.ArgumentsAsString);
         }
         return(Task.Run(() => { return 0; }));
     }));
     whisperCommands.Add("tryrefresh", new Command(async(args) =>
     {
         if (args.isOwner)
         {
             bot.SendWhisper(args.Caller, "Starting refresh");
             try
             {
                 var botTokens  = await TwitchBot.api.V5.Auth.RefreshAuthTokenAsync(Credentials.botRefreshToken, "0osemzvzybmaunf9tvz78iag3sfhlw", TwitchBot.api.Settings.ClientId);
                 var authTokens = await TwitchBot.api.V5.Auth.RefreshAuthTokenAsync(Credentials.authRefreshToken, "0osemzvzybmaunf9tvz78iag3sfhlw", TwitchBot.api.Settings.ClientId);
                 Credentials.UpdateTokens(bot.credentialsPath, botTokens.AccessToken, authTokens.AccessToken, botTokens.RefreshToken, authTokens.RefreshToken);
                 bot.SendWhisper(args.Caller, "Successfully refreshed");
             }
             catch (Exception ex)
             {
                 bot.SendWhisper(args.Caller, $"Error during refresh: {ex.Message}");
                 bot.LogError("TryRefresh", $"Error message: {ex.Message}");
             }
         }
         return(0);
     }));
 }