public JsonValue <AutofillStatus> Status(string word = "") { return(JsonValue.Create(new AutofillStatus { Enabled = AutofillEnabled, IssuerUid = AutofillData?.IssuerUid.Value, IssuerName = AutofillData != null ? ClientUtility.GetClientNameFromUid(Ts3FullClient, AutofillData.IssuerUid) : null, Word = word, Playlists = AutofillData?.Playlists }, StatusToString)); }
public void OnBotChannelChanged() { var channel = ts3FullClient.Book.CurrentChannel(); if (channel == null) { Log.Warn("OnBotChannelChanged: Could not get bot channel"); return; } var clients = ClientUtility.GetClientsInChannel(ts3FullClient, channel.Id) .Where(CheckClientIncludedInVote) .Select(c => c.Uid); clients = clients.Concat(player.WebSocketPipe.Listeners.Select(Uid.To)).Distinct(); var clientList = clients.ToList(); Log.Trace("Relevant for voting: " + string.Join(", ", clientList.Select(uid => ClientUtility.GetClientNameFromUid(ts3FullClient, uid)))); UpdateNeededForUsers(clientList.ToHashSet()); }
public Result CommandVote(ExecutionInformation info, Uid invoker, string command, string args = null) { command = command.ToLower(); if (string.IsNullOrWhiteSpace(command)) { throw new CommandException("No command to vote for given.", CommandExceptionReason.CommandError); } if (!VotableCommands.Commands.TryGetValue(command, out var votableCommand)) { throw new CommandException($"The given command \"{command}\" can't be put up to vote.", CommandExceptionReason.CommandError); } OnBotChannelChanged(); bool voteAdded; bool votesChanged; bool voteCompleted; if (CurrentVotes.TryGetValue(command, out var currentVote)) { if (!string.IsNullOrWhiteSpace(args)) { throw new CommandException( "There is already a vote going on for this command. You can't start another vote for the same command with other parameters right now.", CommandExceptionReason.CommandError); } if (currentVote.Voters.Remove(invoker)) { int count = currentVote.Voters.Count; voteAdded = false; if (count == 0) { Remove(currentVote); votesChanged = true; client.SendChannelMessage($"Removed vote of {ClientUtility.GetClientNameFromUid(ts3FullClient, invoker)} and stopped vote for \"{command}\"."); } else { votesChanged = false; client.SendChannelMessage($"Removed vote of {ClientUtility.GetClientNameFromUid(ts3FullClient, invoker)} for \"{command}\" ({currentVote.Voters.Count} votes of {Needed})"); } voteCompleted = false; } else { currentVote.Voters.Add(invoker); voteAdded = true; client.SendChannelMessage($"Added vote of {ClientUtility.GetClientNameFromUid(ts3FullClient, invoker)} for \"{command}\" ({currentVote.Voters.Count} votes of {Needed})"); votesChanged = false; voteCompleted = CheckAndFire(currentVote); } } else { info.AddModule(CreateCallerInfo()); var(executor, removeOnResourceEnd) = votableCommand.Create(info, command, args); currentVote = new CurrentVoteData(command, executor, removeOnResourceEnd); Add(currentVote); voteAdded = true; currentVote.Voters.Add(invoker); votesChanged = true; client.SendChannelMessage($"{ClientUtility.GetClientNameFromUid(ts3FullClient, invoker)} started vote for \"{command}\" ({currentVote.Voters.Count} votes of {Needed})"); voteCompleted = CheckAndFire(currentVote); } var result = new Result { VoteAdded = voteAdded, VoteComplete = voteCompleted, VotesChanged = votesChanged, VoteCount = currentVote.Voters.Count, VotesNeeded = Needed }; if (currentVote.Command == "skip" && (voteAdded || votesChanged || voteCompleted)) { OnSkipVoteChanged?.Invoke(this, new SkipVoteEventArgs(result)); } return(result); }