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;
|
bool voteIsInitial = false;
|
||||||
string voteCountString = null;
|
string voteCountString = null;
|
||||||
bool voteThresholdReached = false;
|
bool voteThresholdReached = false;
|
||||||
|
IEnumerable<ulong> finalVoters = null; // used only after channel creation
|
||||||
lock (info)
|
lock (info)
|
||||||
{
|
{
|
||||||
if (info.GetTemporaryChannel(guild) != null) return; // channel exists, do nothing
|
if (info.GetTemporaryChannel(guild) != null) return; // channel exists, do nothing
|
||||||
|
@ -88,6 +89,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
if (voteThresholdReached)
|
if (voteThresholdReached)
|
||||||
{
|
{
|
||||||
info.TempChannelLastActivity = DateTime.UtcNow;
|
info.TempChannelLastActivity = DateTime.UtcNow;
|
||||||
|
finalVoters = info.Voting.VoterList;
|
||||||
info.Voting.Reset();
|
info.Voting.Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +122,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
|
|
||||||
await newChannel.SendMessageAsync($"Welcome to <#{newChannel.Id}>!"
|
await newChannel.SendMessageAsync($"Welcome to <#{newChannel.Id}>!"
|
||||||
+ "\nBe aware that this channel is temporary and **will** be deleted later.");
|
+ "\nBe aware that this channel is temporary and **will** be deleted later.");
|
||||||
|
await SendVoterList(guild, newChannel, finalVoters);
|
||||||
newChannelId = newChannel.Id;
|
newChannelId = newChannel.Id;
|
||||||
}
|
}
|
||||||
if (voteIsInitial && !voteThresholdReached)
|
if (voteIsInitial && !voteThresholdReached)
|
||||||
|
@ -154,10 +157,6 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
* channel overrides.
|
* channel overrides.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!newChannelModlist.IsEmpty())
|
|
||||||
{
|
|
||||||
await newChannel.SendMessageAsync("Applying permissions...");
|
|
||||||
}
|
|
||||||
foreach (var item in newChannelModlist.Roles)
|
foreach (var item in newChannelModlist.Roles)
|
||||||
{
|
{
|
||||||
// Evaluate role from data
|
// 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}");
|
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;
|
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>
|
/// <summary>
|
||||||
/// Listens for any message sent to the temporary channel.
|
/// Listens for any message sent to the temporary channel.
|
||||||
/// Updates the corresponding internal value.
|
/// Updates the corresponding internal value.
|
||||||
|
@ -298,7 +314,8 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
{
|
{
|
||||||
bool act;
|
bool act;
|
||||||
string nameTest;
|
string nameTest;
|
||||||
lock (info) {
|
lock (info)
|
||||||
|
{
|
||||||
act = info.Voting.IsSessionExpired();
|
act = info.Voting.IsSessionExpired();
|
||||||
nameTest = info.Config.VoteChannel;
|
nameTest = info.Config.VoteChannel;
|
||||||
if (act) info.Voting.StartCooldown();
|
if (act) info.Voting.StartCooldown();
|
||||||
|
|
|
@ -47,6 +47,11 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
return _votes.Count == 0;
|
return _votes.Count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the list of users who issued a vote.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<ulong> VoterList => _votes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the voting session has expired.
|
/// Checks if the voting session has expired.
|
||||||
/// To be called by the background task. This automatically resets and sets cooldown.
|
/// To be called by the background task. This automatically resets and sets cooldown.
|
||||||
|
@ -80,7 +85,7 @@ namespace Noikoio.RegexBot.Module.VoteTempChannel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
_votes.Clear();
|
_votes = new List<ulong>();
|
||||||
_cooldownStart = null;
|
_cooldownStart = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
<RootNamespace>Noikoio.RegexBot</RootNamespace>
|
<RootNamespace>Noikoio.RegexBot</RootNamespace>
|
||||||
<AssemblyVersion>2.6.3</AssemblyVersion>
|
|
||||||
<Description>Highly configurable Discord moderation bot</Description>
|
<Description>Highly configurable Discord moderation bot</Description>
|
||||||
<Authors>Noikoio</Authors>
|
<Authors>Noikoio</Authors>
|
||||||
<Company />
|
<Company />
|
||||||
<FileVersion>2.6.2</FileVersion>
|
<Version>2.6.4</Version>
|
||||||
<Version>2.6.3</Version>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
|
Loading…
Reference in a new issue