コード例 #1
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);
     }));
 }
コード例 #2
0
        void FillPersonalizedChatCommands()
        {
            chatCommands.Add("winner", new Command(async(args) =>
            {
                if (args.isBroadcaster)
                {
                    if (giveawayQueue.Count == 0 && tier1subs == 0)
                    {
                        bot.SendMessageRaw($"@{args.Caller} no more giveaways");
                        return(0);
                    }
                    if (args.Arguments.Count == 0)
                    {
                        bot.SendMessageRaw($"@{args.Caller} usage: !winner [value] or !winner [username] [value]");
                        return(0);
                    }
                    if (args.Arguments.Count < 2)
                    {
                        if (int.TryParse(args.Arguments[0], out int value))
                        {
                            GiveawayMember g;
                            if (giveawayQueue.Count > 0)
                            {
                                g = giveawayQueue.Dequeue();
                            }
                            else
                            {
                                g = new GiveawayMember($"{tier1subs} tier 1 subs", tier1subs, 1);
                            }
                            int tierMult;
                            if (g.tier < 3)
                            {
                                tierMult = g.tier;
                            }
                            else
                            {
                                tierMult = 6;
                            }
                            int winValue  = value * g.months * tierMult;
                            Random rng    = new Random();
                            var chat      = await bot.GetChatList();
                            int id        = rng.Next(chat.Count);
                            string winner = chat[id].Username;
                            bot.SendMessageRaw($"And the winner of {winValue} coins on behalf of {g.name} is... @{winner}!");
                            if (CheckHouse(winner, g.name))
                            {
                                bot.SendMessageRaw($"When the house wins, EVERYBODY wins! Coins for everyone!");
                                await bot.coinSystem.CoinGiveaway(winValue);
                                bot.SendMessageRaw($"Successfully gave {winValue} {Credentials.currencyName} to everyone in chat");
                            }
                            else
                            {
                                bot.coinSystem.AddCoins(winner, winValue);
                                bot.SendMessageRaw($"Successfully gave {winValue} {Credentials.currencyName} to {winner}, new balance is {bot.coinSystem.GetCoins(winner)} {Credentials.currencyName}");
                            }
                        }
                        else
                        {
                            bot.SendMessageRaw($"@{args.Caller} usage: !winner [value]");
                        }
                    }
                    else
                    {
                        if (bot.coinSystem.CheckKey(args.Arguments[0]))
                        {
                            if (int.TryParse(args.Arguments[1], out int value))
                            {
                                string house  = args.Arguments[0];
                                Random rng    = new Random();
                                var chat      = await bot.GetChatList();
                                int id        = rng.Next(chat.Count);
                                string winner = chat[id].Username;
                                bot.SendMessageRaw($"And the winner of {value} {Credentials.currencyName} is... @{winner}!");
                                if (CheckHouse(winner, house))
                                {
                                    bot.SendMessageRaw("When the house wins, EVERYBODY wins! Coins for everyone!");
                                    await bot.coinSystem.CoinGiveaway(value);
                                    bot.SendMessageRaw($"Successfully gave {value} {Credentials.currencyName} to everyone in chat");
                                }
                                else
                                {
                                    bot.coinSystem.AddCoins(winner, value);
                                    bot.SendMessageRaw($"Successfully gave {value} {Credentials.currencyName} to @{winner}, new balance is {bot.coinSystem.GetCoins(winner)}");
                                }
                            }
                            else
                            {
                                bot.SendMessageRaw($"@{args.Caller} usage: !winner [username] [value]");
                            }
                        }
                        else
                        {
                            bot.SendMessageRaw($"@{args.Caller} usage: !winner [username] [value]");
                        }
                    }
                }
                return(0);
            }, "Pulls a random winner of a coin giveaway from chat. Broadcaster only. Syntax: !winner [dice roll] or !winner [house] [value]\n"));
            chatCommands.Add("giveaways", new Command(async(args) =>
            {
                if (args.isBroadcaster)
                {
                    string msg = "";
                    foreach (var g in giveawayQueue)
                    {
                        msg += $"{g.name}: {g.months} months, tier {g.tier}\n";
                    }
                    if (tier1subs > 0)
                    {
                        msg += $"{tier1subs} tier 1 subs\n";
                    }
                    var paste = await bot.PasteOnPasteBin(msg, $"{DateTime.Now.Year}.{DateTime.Now.Month}.{DateTime.Now.Day} IggiBot giveaways");
                    bot.SendWhisper(args.Caller, paste);
                    return(5);
                }
                return(0);
            }, "Posts giveaway list on pastebin. Broadcaster only. Syntax: !giveaways\n"));
            chatCommands.Add("kraken", new Command(async(args) =>
            {
                if (args.isBroadcaster || args.isModerator || args.isOwner)
                {
                    bot.SendMessageRaw($"Release the Kraken!");
                    totalKrakens += nextKraken;
                    nextKraken   += 11;
                    await UpdateFiles();
                }
                return(0);
            }, "Releases the Kraken! Moderator+ only. Syntax: !kraken\n"));
            chatCommands.Add("missedcoins", new Command(async(args) =>
            {
                if (args.isBroadcaster || args.isModerator || args.isOwner)
                {
                    if (args.Arguments.Count > 0)
                    {
                        if (int.TryParse(args.Arguments[0], out int value))
                        {
                            missedCoins += value;
                            await UpdateFiles();
                        }
                        else if (float.TryParse(args.Arguments[0], out float valueF))
                        {
                            missedCoins += valueF;
                            await UpdateFiles();
                        }
                    }
                }
                return(0);
            }, "Adds missed extra coins. Moderator+ only. Syntax: !missedcoins [float value]\n"));

            chatCommands.Remove("winner");
            chatCommands.Remove("giveaways");
        }