public async Task CoinGiveaway(int value) { var list = await bot.GetChatList(); foreach (var u in list) { AddCoins(u.Username, value); } }
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"); }
public CoinSystem(TwitchBot Bot, string userStatsPath, string backupDirectoryPath) { userStats = new Dictionary <string, UserStats>(); userStatsTxt = new TxtFile(userStatsPath); LoadStats(); this.backupDirectoryPath = backupDirectoryPath; bot = Bot; cache = new SubscriberCache(bot); passiveCoins = new Timer(async(sender) => { if (bot.online == false) { return; } var list = await bot.GetChatList(); if (list != null && list.Count > 0) { foreach (var u in list) { int subTier = await cache.GetOrCreate(u.Username); switch (subTier) { case 0: AddCoins(u.Username, 1); break; case 1: AddCoins(u.Username, 2); break; case 2: AddCoins(u.Username, 3); break; case 3: AddCoins(u.Username, 6); break; } } if (saveCounter >= 5) { SaveStats(); saveCounter = 0; } saveCounter++; } }, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); /*chatTime = new Timer(async (sender) => * { * if (bot.online == false) return; * var list = await bot.GetChatList(); * if (list != null) * { * foreach (var u in list) * { * AddTime(u.Username, 1); * } * } * },null,TimeSpan.FromMinutes(1),TimeSpan.FromMinutes(1)); */ }