Adds role specific channels.
Read ME update Updating tile of role will update revelant channels and roles. Added command examples. Fixese leaks
This commit is contained in:
@@ -88,7 +88,7 @@ namespace EventBot.Modules
|
||||
.Aggregate(true, (a, r) => a && r))
|
||||
.SelectMany(c => c.Aliases.Select(a => new { CI = c, MA = (c.Aliases[0] == a), A = a }).Reverse())
|
||||
.Select((e, i) => new { Command = e, Index = i })
|
||||
.GroupBy(o => o.Index / 20)
|
||||
.GroupBy(o => o.Index / 15)
|
||||
.Select(g => g.Select(o => o.Command));
|
||||
|
||||
var pager = new PaginatedMessage()
|
||||
@@ -130,6 +130,9 @@ namespace EventBot.Modules
|
||||
embed.AddField("Parameters",
|
||||
string.Join("\r\n", command.Parameters.Select(p => $"`{p.FormatParameter()}` *(Type: {p.FormatParameterType()})* - **{p.Summary}** {(p.IsRemainder ? "_No quotes are needed, when providing this parameter._" : "")}" ))
|
||||
);
|
||||
var examples = command.Attributes.Where(a => a is ExampleAttribute).Select(a => ((ExampleAttribute)a).Use).ToArray();
|
||||
if (examples.Length != 0)
|
||||
embed.AddField("Examples", $"```{string.Join("\r\n", examples)}```");
|
||||
|
||||
await ReplyAsync($"I got this information about command `{commandAlias}`:", embed: embed.Build());
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ using System.Linq;
|
||||
using EventBot.Entities;
|
||||
using Discord.WebSocket;
|
||||
using Discord.Addons.Interactive;
|
||||
using EventBot.Attributes;
|
||||
|
||||
namespace EventBot.Modules
|
||||
{
|
||||
@@ -28,6 +29,9 @@ namespace EventBot.Modules
|
||||
[Alias("j")]
|
||||
[Name("Join event")]
|
||||
[Summary("Joins latest or specified event with specified event role.")]
|
||||
[Example("join :slight_smile:")]
|
||||
[Example("join 5 \"John Smith\"")]
|
||||
[Example("join :gun: \"Tpr. James\" 2")]
|
||||
public async Task JoinEvent(
|
||||
[Summary("Role emote or role ID to join the most recent event.")] string emoteOrId,
|
||||
[Summary("Extra information that might be needed by organizers.")] string extraInformation = null,
|
||||
@@ -56,6 +60,7 @@ namespace EventBot.Modules
|
||||
[RequireUserPermission(GuildPermission.Administrator, Group = "Permission")]
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[Group("event")]
|
||||
//[Alias("e")]
|
||||
[Name("Event management")]
|
||||
public class EventManagementModule : InteractiveBase<SocketCommandContext>
|
||||
{
|
||||
@@ -67,6 +72,7 @@ namespace EventBot.Modules
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("config logchannel")]
|
||||
[Name("Configure logging channel")]
|
||||
[Summary("Sets logging channel for role changes.")]
|
||||
@@ -83,6 +89,7 @@ namespace EventBot.Modules
|
||||
await s;
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("config partrole")]
|
||||
[Name("Configure participant role")]
|
||||
[Summary("Sets discord role to assign when the user selects a role.")]
|
||||
@@ -99,10 +106,35 @@ namespace EventBot.Modules
|
||||
await s;
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("config category")]
|
||||
[Name("Configure auto channel category")]
|
||||
[Summary("Configures auto channel category, where new channels will be created for each role.")]
|
||||
public async Task ConfigureParticipantCategory(
|
||||
[Summary("Category to use when making channels for roles.")] ICategoryChannel category = null)
|
||||
{
|
||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||
if (guild == null)
|
||||
throw new Exception("This command must be executed inside a discord server.");
|
||||
if (category == null)
|
||||
{
|
||||
guild.AutoRoleChannelCategoryId = 0;
|
||||
await ReplyAsync("No channels and discord roles will be created for event roles.");
|
||||
} else
|
||||
{
|
||||
guild.AutoRoleChannelCategoryId = category.Id;
|
||||
await ReplyAsync($"Bot will create discord roles and channels for each new role inside `{category.Name}` category.");
|
||||
}
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Priority(1)]
|
||||
[Command("new")]
|
||||
[Alias("add", "create")]
|
||||
[Name("Create event")]
|
||||
[Summary("Creates a new event.")]
|
||||
[Example("event new \"The event\" \"This is going to be a very hard event to organize.\"")]
|
||||
[Example("event new \"Departmental chaos\" \"This event is about departmental workers rising against heads. Please provide your character name during registration.\" Detailed")]
|
||||
public async Task CreateEvent(
|
||||
[Summary("Title for the event.")] string title,
|
||||
[Summary("Description for the event.")] string description,
|
||||
@@ -124,6 +156,7 @@ namespace EventBot.Modules
|
||||
await ReplyAsync($"Created new {@event.Type} event `{title}`, with description: `{description}`. Its ID is `{@event.Id}`.");
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("update title")]
|
||||
[Name("Update event's title")]
|
||||
[Summary("Updates the event's title.")]
|
||||
@@ -142,6 +175,7 @@ namespace EventBot.Modules
|
||||
await ReplyAsync($"Updated event's (`{@event.Id}`) title to `{@event.Title}`");
|
||||
await _events.UpdateEventMessage(@event);
|
||||
}
|
||||
[Priority(2)]
|
||||
[Command("update description")]
|
||||
[Alias("update desc")]
|
||||
[Name("Update event's description")]
|
||||
@@ -162,9 +196,12 @@ namespace EventBot.Modules
|
||||
await _events.UpdateEventMessage(@event);
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("update type")]
|
||||
[Name("Update event's type")]
|
||||
[Summary("Updates the event type.")]
|
||||
[Example("event update type Quick")]
|
||||
[Example("event update type Detailed 3")]
|
||||
public async Task UpdateEventType(
|
||||
[Summary("Type of event registration.")] Event.EventParticipactionType type,
|
||||
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
||||
@@ -186,10 +223,14 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role new")]
|
||||
[Alias("role add", "role create")]
|
||||
[Name("Add role")]
|
||||
[Summary("Adds a new role to the event.")]
|
||||
[Example("event role new \"ERT\" \"Emergency response team that recovers the artifact.\" :gun:")]
|
||||
[Example("event role new \"Ninja\" \"To sneak around various corners of the station.\" :fire: 1")]
|
||||
[Example("event role new \"Mercenaries\" \"To go on the station and do stuff.\" :fingers_crossed: 6 2")]
|
||||
public async Task NewEventRole(
|
||||
[Summary("Title of the role.")] string title,
|
||||
[Summary("Description of the role.")] string description,
|
||||
@@ -219,11 +260,21 @@ namespace EventBot.Modules
|
||||
Emote = parsedEmote.ToString(),
|
||||
Event = @event
|
||||
};
|
||||
if(@event.Guild.AutoRoleChannelCategoryId != 0)
|
||||
{
|
||||
var channel = await Context.Guild.CreateTextChannelAsync(er.ChannelName, o => o.CategoryId = @event.Guild.AutoRoleChannelCategoryId);
|
||||
var role = await Context.Guild.CreateRoleAsync(er.Title);
|
||||
await channel.AddPermissionOverwriteAsync(role, new OverwritePermissions(viewChannel: PermValue.Allow, sendMessages: PermValue.Allow));
|
||||
er.RoleId = role.Id;
|
||||
er.ChannelId = channel.Id;
|
||||
}
|
||||
|
||||
_database.Add(er);
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"Added event role `{er.Id}` for event `{er.Event.Id}`, title: `{er.Title}`, description: `{er.Description}`, slots: `{er.MaxParticipants}`, emote: {er.Emote}");
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role update title")]
|
||||
[Name("Update role's title")]
|
||||
[Summary("Updates the role's title.")]
|
||||
@@ -237,11 +288,16 @@ namespace EventBot.Modules
|
||||
throw new Exception("This event is finalized. Please make a new event.");
|
||||
eventRole.Title = title;
|
||||
var s = _database.SaveChangesAsync();
|
||||
if (eventRole.ChannelId != 0)
|
||||
await Context.Guild.GetTextChannel(eventRole.ChannelId).ModifyAsync(p => p.Name = eventRole.ChannelName);
|
||||
if (eventRole.RoleId != 0)
|
||||
await Context.Guild.GetRole(eventRole.RoleId).ModifyAsync(p => p.Name = eventRole.Title);
|
||||
await ReplyAsync($"Updated event role `{eventRole.Id}`'s title to `{eventRole.Title}`");
|
||||
await s;
|
||||
await _events.UpdateEventMessage(eventRole.Event);
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role update description")]
|
||||
[Alias("role update desc")]
|
||||
[Name("Update role's description")]
|
||||
@@ -261,6 +317,7 @@ namespace EventBot.Modules
|
||||
await _events.UpdateEventMessage(eventRole.Event);
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role update slots")]
|
||||
[Name("Update role's slots")]
|
||||
[Summary("Updates a role's maximum participants count.")]
|
||||
@@ -280,6 +337,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role update emote")]
|
||||
[Name("Update role's role")]
|
||||
[Summary("Updates a role's emote.")]
|
||||
@@ -335,6 +393,33 @@ namespace EventBot.Modules
|
||||
|
||||
await ReplyAsync(embed: embed.Build());
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role delete")]
|
||||
[Alias("role remove")]
|
||||
[Name("Delete role")]
|
||||
[Summary("Deletes role and all information about it.")]
|
||||
public async Task EventRoleDelete(
|
||||
[Summary("Role you wish to delete.")] EventRole eventRole)
|
||||
{
|
||||
if (!(Context.User is SocketGuildUser guildUser))
|
||||
throw new Exception("This command must be executed inside a discord server.");
|
||||
if (eventRole == null)
|
||||
throw new Exception("Please provide the correct role, this one does not exist.");
|
||||
if (eventRole.Event.MessageId != 0)
|
||||
throw new Exception("Can't remove role from open event.");
|
||||
|
||||
foreach (var p in eventRole.Participants)
|
||||
await _events.RemoveParticipant(p, guildUser);
|
||||
if(eventRole.ChannelId != 0)
|
||||
await Context.Guild.GetTextChannel(eventRole.ChannelId)?.DeleteAsync();
|
||||
if (eventRole.RoleId != 0)
|
||||
await Context.Guild.GetRole(eventRole.RoleId)?.DeleteAsync();
|
||||
_database.Remove(eventRole);
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"Role {eventRole.Title} has been deleted, and it's participants removed.");
|
||||
}
|
||||
|
||||
[Priority(1)]
|
||||
[Command("role")]
|
||||
[Alias("role info")]
|
||||
@@ -361,6 +446,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
}
|
||||
|
||||
[Priority(1)]
|
||||
[Command("open")]
|
||||
[Alias("start", "begin")]
|
||||
[Name("Open event")]
|
||||
@@ -394,7 +480,9 @@ namespace EventBot.Modules
|
||||
throw new Exception("Event type in not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Priority(1)]
|
||||
[Command("close")]
|
||||
[Alias("stop", "end")]
|
||||
[Name("Close event")]
|
||||
@@ -417,6 +505,8 @@ namespace EventBot.Modules
|
||||
await ReplyAsync($"Event's `{@event.Id}` registration has been closed, its registration message will now be normal message.");
|
||||
}
|
||||
|
||||
|
||||
[Priority(1)]
|
||||
[Command("finalize")]
|
||||
[Alias("archive")]
|
||||
[Name("Archive event")]
|
||||
@@ -441,9 +531,18 @@ namespace EventBot.Modules
|
||||
var user = Context.Guild.GetUser(participant.UserId);
|
||||
await user.RemoveRoleAsync(Context.Guild.GetRole(@event.Guild.ParticipantRoleId));
|
||||
}
|
||||
foreach (var role in @event.Roles)
|
||||
{
|
||||
if (role.ChannelId != 0)
|
||||
await Context.Guild.GetTextChannel(role.ChannelId)?.DeleteAsync();
|
||||
if (role.RoleId != 0)
|
||||
await Context.Guild.GetRole(role.RoleId)?.DeleteAsync();
|
||||
|
||||
}
|
||||
await ReplyAsync($"Everyone's roles have been removed. I hope it was fun!");
|
||||
}
|
||||
|
||||
[Priority(1)]
|
||||
[Command("list")]
|
||||
[Alias("all")]
|
||||
[Name("Lists events")]
|
||||
@@ -478,9 +577,14 @@ namespace EventBot.Modules
|
||||
await PagedReplyAsync(pager);
|
||||
}
|
||||
|
||||
|
||||
[Priority(2)]
|
||||
[Command("participant add")]
|
||||
[Name("Add participant")]
|
||||
[Summary("Add user to event role. Acts like join command.")]
|
||||
[Summary("Add user to event role. Acts like join command. Works even if registration is closed.")]
|
||||
[Example("participant add \"Mini Moose#6944\" :slight_smile:")]
|
||||
[Example("participant add Arrow768#3092 5 \"John Smith\"")]
|
||||
[Example("participant add 183658981019877376 :gun: \"Tpr. James\" 2")]
|
||||
public async Task EventParticipantAdd(
|
||||
[Summary("User ID or discord mention.")] IUser user,
|
||||
[Summary("Role emote or role ID to join.")] string emoteOrId,
|
||||
@@ -507,6 +611,7 @@ namespace EventBot.Modules
|
||||
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("participant remove")]
|
||||
[Alias("participant delete")]
|
||||
[Name("Remove participant")]
|
||||
@@ -521,25 +626,15 @@ namespace EventBot.Modules
|
||||
throw new Exception("No events were found for this discord server.");
|
||||
if (!@event.Active)
|
||||
throw new Exception("This event is finalized. Please make a new event.");
|
||||
|
||||
if (!(user is IGuildUser guildUser))
|
||||
if (!(user is IGuildUser guildUser) || !(Context.User is IGuildUser initiator))
|
||||
throw new Exception("This command must be executed inside a discord server.");
|
||||
|
||||
var participant = @event.Participants.FirstOrDefault(p => p.UserId == guildUser.Id);
|
||||
_database.Remove(participant);
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle($"{user} been removed from event `{@event.Title}`, by {Context.User}.")
|
||||
.WithDescription($"Their role was: `{participant.Role.Title}`")
|
||||
.WithColor(Color.Red);
|
||||
if (participant.UserData != null)
|
||||
embed.AddField("Provided details", $"`{participant.UserData}`");
|
||||
|
||||
await _events.RemoveParticipant(guildUser, @event, initiator);
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"{guildUser} has been removed from event.");
|
||||
await _events.UpdateEventMessage(@event);
|
||||
if (@event.Guild.EventRoleConfirmationChannelId != 0)
|
||||
await (await ((IGuild)Context.Guild).GetTextChannelAsync(@event.Guild.EventRoleConfirmationChannelId)).SendMessageAsync(embed: embed.Build());
|
||||
if (@event.Guild.ParticipantRoleId != 0)
|
||||
await guildUser.RemoveRoleAsync(Context.Guild.GetRole(@event.Guild.ParticipantRoleId));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user