public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback) { string url = parameters[0]; if (url.ToLower().StartsWith("[url]")) { url = url.Substring("[url]".Length, url.Length - ("[/url]".Length + "[url]".Length)); } url = url.Contains("v=") ? url : $"https://youtube.com/watch?v={url}"; YoutubeClient youtube = new YoutubeClient(); Video video = youtube.Videos.GetAsync(url).Result; string title = video.Title; string author = video.Author; long likeCount = video.Engagement.LikeCount; long dislikeCount = video.Engagement.DislikeCount; long views = video.Engagement.ViewCount; TimeSpan duration = video.Duration; double ratio = double.NaN; if (likeCount != 0 || dislikeCount != 0) { ratio = (double)likeCount / ((double)likeCount + dislikeCount); } string yt = ColorCoder.ColorText(Color.DarkRed, "YouTube"); string likes = ColorCoder.ColorText(Color.DarkGreen, $"↑{likeCount}"); string dislikes = ColorCoder.ColorText(Color.Red, $"↓{dislikeCount}"); string ratioStr = $"{ratio:0%}"; if (ratio == 1) { ratioStr = ColorCoder.ColorText(Color.FromHex("22ee22"), $"↑{ratioStr}↑"); } else if (ratio >= 0.95) { ratioStr = ColorCoder.ColorText(Color.DarkGreen, ratioStr); } else if (ratio >= 0.85) { ratioStr = ColorCoder.ColorText(Color.Yellow, ratioStr); } else { ratioStr = ColorCoder.ColorText(Color.Red, ratioStr); } Parent.StatSettings.YouTubeLinksFetched++; string response = $"{yt} ⇒ [url={url}]{title}[/url] [{duration}] from [B]{author}[/B] | {likes} | {dislikes} | {ratioStr}"; Parent.IgnoreSelfTextMessage(response); messageCallback(response); }
public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback) { if (parameters.Count == 0) { string toPrint = $"All commands are listed below ({ChatCommandHandler.ChatCommands.Count}):"; foreach (ChatCommand cmd in ChatCommandHandler.ChatCommands.OrderBy((cmd) => cmd.CommandPrefix)) { string commandHelp = $"\n{ColorCoder.Bold($"{Settings.ChatCommandPrefix}{cmd.CommandPrefix}")}:\t-\t{cmd.GetUsageDescription(cmd.CommandPrefix, parameters)}"; if (!cmd.CanExecute(evt.InvokerUniqueId, cmd.CommandPrefix, parameters)) { commandHelp = ColorCoder.ColorText(Color.LightRed, commandHelp); } toPrint += commandHelp; } messageCallback.Invoke(toPrint); } else { string requestedCommand = parameters[0]; parameters = parameters.Skip(1).ToList(); foreach (ChatCommand cmd in ChatCommandHandler.ChatCommands) { if (cmd.CommandPrefix == requestedCommand || cmd.CommandAliases.Contains(requestedCommand)) { ChatCommand chatCommand = (ChatCommand)Activator.CreateInstance(cmd.GetType()); chatCommand.Parent = Parent; chatCommand.Settings = Settings; try { if (!chatCommand.CanExecute(evt.InvokerUniqueId, requestedCommand, parameters)) { messageCallback.Invoke(ColorCoder.ErrorBright($"You don't have access to view the help of this command")); break; } if (!chatCommand.IsValidCommandSyntax(requestedCommand, parameters)) { //parameters = new List<string>(); } } catch (CommandParameterInvalidFormatException) {} string helpUsage = Settings.ChatCommandPrefix + chatCommand.GetUsageSyntax(requestedCommand, parameters); string helpDescription = chatCommand.GetUsageDescription(requestedCommand, parameters); string aliases = string.Join(", ", chatCommand.CommandAliases); aliases = string.IsNullOrEmpty(aliases) ? "<None>" : aliases; messageCallback.Invoke($"Help for command {ColorCoder.Bold($"'{chatCommand.CommandPrefix}'")}:\n\t{ColorCoder.Bold("Aliases:")} {aliases}\n\t{ColorCoder.Bold("Usage:")} {helpUsage}\n\t{ColorCoder.Bold("Description:")} {helpDescription}"); break; } } } }
public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback) { int amountToGamble = 0; StatisticSettings stats = Parent.StatSettings; if (RequestedStats) { RouletteStatistics displayStats; string toPrint; if (RequestedStatsName != null && RequestedStatsName == "all") { displayStats = stats.Roulette; toPrint = "Global roulette stats:"; } else { string userUid = evt.InvokerUniqueId; string userName = evt.InvokerName; if (RequestedStatsName != null) { Client user = Parent.Client.GetClientByNamePart(RequestedStatsName); userUid = user.UniqueId; userName = user.Nickname; } CheckHasStatisticsEntry(userUid); displayStats = stats.RouletteIndividual[userUid]; toPrint = $"Roulette stats for {ColorCoder.Username(userName)}:"; } int won = displayStats.GamesWon; int lost = displayStats.GamesLost; double ratioPercent = (double)won * 100 / (lost + won); string ratioPercentStr; if (double.IsNaN(ratioPercent)) { ratioPercentStr = "-%"; } else { ratioPercentStr = ColorCoder.ColorPivotPercent(ratioPercent, 50); } toPrint += $"\n\tGames: {won + lost} ({ColorCoder.SuccessDim($"{won}W")}, {ColorCoder.ErrorBright($"{lost}L")} | {ratioPercentStr})"; int balanceWon = displayStats.PointsWon; int balanceLost = displayStats.PointsLost; int balanceDiff = balanceWon - balanceLost; string balanceDiffStr = ColorCoder.ColorPivot(balanceDiff, 0); toPrint += $"\n\tPoints: {balanceDiffStr} ({ColorCoder.SuccessDim($"+{balanceWon} won")}, {ColorCoder.ErrorBright($"-{balanceLost} lost")})"; int jackpots = displayStats.Jackpots; int jackpotPoints = displayStats.JackpotsPointsWon; toPrint += $"\n\tJackpots: {jackpots} ({ColorCoder.SuccessDim($"+{jackpotPoints} bonus")})"; double rolls = displayStats.Rolls; string rollsStr = (won + lost) == 0 ? "-" : $"{rolls / (won + lost):0.####}"; toPrint += $"\n\tAvg. Roll: {rollsStr}"; messageCallback.Invoke(toPrint); return; } if (!Settings.RouletteEnabled) { messageCallback.Invoke(ColorCoder.ErrorBright($"The casino is currently closed, sorry {ColorCoder.Username(evt.InvokerName)}!")); return; } CooldownManager.ThrowIfCooldown(evt.InvokerUniqueId, "command:roulette"); int currentBalance = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId); if (currentBalance > Settings.EcoSoftBalanceLimit) { messageCallback.Invoke(ColorCoder.ErrorBright($"You can't gamble while being over {ColorCoder.Bold($"{Settings.EcoSoftBalanceLimit} {Settings.EcoPointUnitName}")}, {ColorCoder.Username(evt.InvokerName)}")); return; } if (IsAll) { amountToGamble = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId); } else if (IsPercent) { if (Amount > 100) { messageCallback.Invoke(ColorCoder.ErrorBright($"You can't gamble away more than you own, {ColorCoder.Username(evt.InvokerName)}")); return; } amountToGamble = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId); amountToGamble = (int)Math.Ceiling(amountToGamble * ((double)Amount / 100)); } else { int balanceAfterPay = EconomyManager.GetUserBalanceAfterPaying(evt.InvokerUniqueId, (int)Amount); if (balanceAfterPay < 0) { messageCallback.Invoke(ColorCoder.ErrorBright($"You don't have enough to gamble away '{ColorCoder.Bold($"{Amount} {Settings.EcoPointUnitName}")}', {ColorCoder.Username(evt.InvokerName)}")); return; } amountToGamble = (int)Amount; } if (amountToGamble <= 0) { messageCallback.Invoke(ColorCoder.ErrorBright($"You don't have any cash on you, get out of my casino!")); return; } CooldownManager.SetCooldown(evt.InvokerUniqueId, "command:roulette", Settings.RouletteCooldown); double winChancePercent = Settings.RouletteWinChancePercent; double jackpotChancePercent = Settings.RouletteJackpotChancePercent; if (amountToGamble == Settings.EcoSoftBalanceLimit) { winChancePercent += 1; } winChancePercent /= 100; jackpotChancePercent /= 100; Random r = new Random(); double chosenValue = r.NextDouble(); string resultLogMsg = $"({chosenValue:0.#####} | win {winChancePercent:0.#####} | jackpot {jackpotChancePercent:0.#####})"; Parent.LastRouletteResult = resultLogMsg; Parent.LogMessage($"Roulette result: {resultLogMsg}"); int changeBalanceAmount; string message; string ptsUnit = Settings.EcoPointUnitName; CheckHasStatisticsEntry(evt.InvokerUniqueId); RouletteStatistics indivStats = stats.RouletteIndividual[evt.InvokerUniqueId]; RouletteStatistics allStats = stats.Roulette; allStats.Rolls += chosenValue; indivStats.Rolls += chosenValue; if (chosenValue < winChancePercent) //User won the roulette { double yield = Settings.RouletteWinYieldMultiplier; changeBalanceAmount = (int)Math.Floor(amountToGamble * (yield - 1)); if (chosenValue < jackpotChancePercent) { allStats.Jackpots++; int jackpotPoints = (int)(changeBalanceAmount * Settings.RouletteJackpotMultiplier); allStats.JackpotsPointsWon += jackpotPoints - changeBalanceAmount; indivStats.JackpotsPointsWon += jackpotPoints - changeBalanceAmount; changeBalanceAmount = jackpotPoints; messageCallback.Invoke(ColorCoder.Success($"\t-\t JACKPOT! Your reward has just been tripled!\t-\t")); } allStats.GamesWon++; indivStats.GamesWon++; allStats.PointsWon += changeBalanceAmount; indivStats.PointsWon += changeBalanceAmount; message = ColorCoder.ColorText(Color.DarkGreen, ColorCoder.Username(evt.InvokerName) + $" won {ColorCoder.Bold(changeBalanceAmount.ToString())} {ptsUnit} in roulette and now has {ColorCoder.Bold((currentBalance + changeBalanceAmount).ToString())} {ptsUnit} forsenPls ({chosenValue:0.####})"); } else { changeBalanceAmount = -amountToGamble; allStats.GamesLost++; indivStats.GamesLost++; allStats.PointsLost += amountToGamble; indivStats.PointsLost += amountToGamble; message = ColorCoder.ErrorBright(ColorCoder.Username(evt.InvokerName) + $" lost {ColorCoder.Bold(amountToGamble.ToString())} {ptsUnit} in roulette and now has {ColorCoder.Bold((currentBalance + changeBalanceAmount).ToString())} {ptsUnit} FeelsBadMan ({chosenValue:0.####})"); } stats.DelayedSave(); EconomyManager.ChangeBalanceForUser(evt.InvokerUniqueId, changeBalanceAmount); messageCallback.Invoke(message); }