Display voter list in new temporary channel
This commit is contained in:
parent
fd35a3aa78
commit
762950062d
3 changed files with 72 additions and 52 deletions
|
@ -64,6 +64,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
bool voteIsInitial = false;
|
||||
string voteCountString = null;
|
||||
bool voteThresholdReached = false;
|
||||
IEnumerable<ulong> finalVoters = null; // used only after channel creation
|
||||
lock (info)
|
||||
{
|
||||
if (info.GetTemporaryChannel(guild) != null) return; // channel exists, do nothing
|
||||
|
@ -88,6 +89,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
if (voteThresholdReached)
|
||||
{
|
||||
info.TempChannelLastActivity = DateTime.UtcNow;
|
||||
finalVoters = info.Voting.VoterList;
|
||||
info.Voting.Reset();
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +122,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
|
||||
await newChannel.SendMessageAsync($"Welcome to <#{newChannel.Id}>!"
|
||||
+ "\nBe aware that this channel is temporary and **will** be deleted later.");
|
||||
await SendVoterList(guild, newChannel, finalVoters);
|
||||
newChannelId = newChannel.Id;
|
||||
}
|
||||
if (voteIsInitial && !voteThresholdReached)
|
||||
|
@ -154,10 +157,6 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
* channel overrides.
|
||||
*/
|
||||
|
||||
if (!newChannelModlist.IsEmpty())
|
||||
{
|
||||
await newChannel.SendMessageAsync("Applying permissions...");
|
||||
}
|
||||
foreach (var item in newChannelModlist.Roles)
|
||||
{
|
||||
// Evaluate role from data
|
||||
|
@ -217,13 +216,30 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
await newChannel.SendMessageAsync($":x: Unable to set on `{u.Username}`: {ex.Message}");
|
||||
}
|
||||
}
|
||||
if (!newChannelModlist.IsEmpty())
|
||||
{
|
||||
await newChannel.SendMessageAsync("Permission application process has completed.");
|
||||
}
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
private async Task SendVoterList(SocketGuild g, RestTextChannel ch, IEnumerable<ulong> voters)
|
||||
{
|
||||
var names = new System.Text.StringBuilder();
|
||||
foreach (var item in voters)
|
||||
{
|
||||
var u = g.GetUser(item);
|
||||
if (u == null)
|
||||
{
|
||||
names.AppendLine("Unknown user with ID " + item);
|
||||
}
|
||||
else
|
||||
{
|
||||
names.Append(u.Username + "#" + u.Discriminator);
|
||||
if (u.Nickname != null) names.Append(" (" + u.Nickname + ")");
|
||||
names.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
await ch.SendMessageAsync("Persons who voted to create this channel:\n" + names.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Listens for any message sent to the temporary channel.
|
||||
/// Updates the corresponding internal value.
|
||||
|
@ -298,7 +314,8 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
{
|
||||
bool act;
|
||||
string nameTest;
|
||||
lock (info) {
|
||||
lock (info)
|
||||
{
|
||||
act = info.Voting.IsSessionExpired();
|
||||
nameTest = info.Config.VoteChannel;
|
||||
if (act) info.Voting.StartCooldown();
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
return _votes.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the list of users who issued a vote.
|
||||
/// </summary>
|
||||
public IEnumerable<ulong> VoterList => _votes;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the voting session has expired.
|
||||
/// To be called by the background task. This automatically resets and sets cooldown.
|
||||
|
@ -80,7 +85,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
|||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_votes.Clear();
|
||||
_votes = new List<ulong>();
|
||||
_cooldownStart = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RootNamespace>Noikoio.RegexBot</RootNamespace>
|
||||
<AssemblyVersion>2.6.3</AssemblyVersion>
|
||||
<Description>Highly configurable Discord moderation bot</Description>
|
||||
<Authors>Noikoio</Authors>
|
||||
<Company />
|
||||
<FileVersion>2.6.2</FileVersion>
|
||||
<Version>2.6.3</Version>
|
||||
<Version>2.6.4</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
|
|
Loading…
Reference in a new issue