Compare commits
12 Commits
master
...
373f1ec2eb
Author | SHA1 | Date | |
---|---|---|---|
|
373f1ec2eb | ||
|
96ebf7b07c | ||
|
45878f5fcc | ||
|
104ea6e7bd | ||
|
0447308f40 | ||
|
e3d69dd9c5 | ||
|
e07853a8dd | ||
|
d478e550ba | ||
|
e094766bf4 | ||
|
9c7d370b5b | ||
|
a67f6f1666 | ||
|
8d0093f1d3 |
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace EventBot.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||
class ExampleAttribute : Attribute
|
||||
{
|
||||
public string Use { get; set; }
|
||||
public ExampleAttribute(string use)
|
||||
{
|
||||
Use = use;
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace EventBot.Entities
|
||||
{
|
||||
@@ -16,8 +15,6 @@ namespace EventBot.Entities
|
||||
public string Description { get; set; }
|
||||
public string Emote { get; set; }
|
||||
public int MaxParticipants { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
public ulong RoleId { get; set; }
|
||||
public int EventId { get; set; }
|
||||
[ForeignKey("EventId")]
|
||||
public virtual Event Event { get; set; }
|
||||
@@ -25,8 +22,6 @@ namespace EventBot.Entities
|
||||
public int ParticipantCount => Participants == null ? 0 : Participants.Count;
|
||||
public int ReamainingOpenings => MaxParticipants < 0 ? 1 : MaxParticipants - ParticipantCount;
|
||||
|
||||
public string ChannelName => Regex.Replace(Title.Replace(' ', '-'), "(?!\\w)", "");
|
||||
|
||||
public int SortNumber
|
||||
{
|
||||
get
|
||||
|
@@ -12,7 +12,6 @@ namespace EventBot.Entities
|
||||
public string Prefix { get; set; }
|
||||
public ulong EventRoleConfirmationChannelId { get; set; }
|
||||
public ulong ParticipantRoleId { get; set; }
|
||||
public ulong AutoRoleChannelCategoryId { get; set; }
|
||||
public virtual ICollection<Event> Events { get; set; }
|
||||
|
||||
}
|
||||
|
@@ -9,15 +9,15 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Addons.Interactive" Version="1.0.1" />
|
||||
<PackageReference Include="Discord.Net" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.design" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.design" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -1,147 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using EventBot.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace EventBot.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseService))]
|
||||
[Migration("20190620075923_AutoRolesAndChannels")]
|
||||
partial class AutoRolesAndChannels
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.Event", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<bool>("Active");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<ulong>("GuildId");
|
||||
|
||||
b.Property<ulong>("MessageChannelId");
|
||||
|
||||
b.Property<ulong>("MessageId");
|
||||
|
||||
b.Property<DateTime>("Opened");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.Property<int>("Type");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GuildId");
|
||||
|
||||
b.ToTable("Events");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventParticipant", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("EventId");
|
||||
|
||||
b.Property<int>("EventRoleId");
|
||||
|
||||
b.Property<string>("UserData");
|
||||
|
||||
b.Property<ulong>("UserId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EventId");
|
||||
|
||||
b.HasIndex("EventRoleId");
|
||||
|
||||
b.ToTable("EventParticipants");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventRole", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("ChannelId");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<string>("Emote");
|
||||
|
||||
b.Property<int>("EventId");
|
||||
|
||||
b.Property<int>("MaxParticipants");
|
||||
|
||||
b.Property<ulong>("RoleId");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EventId");
|
||||
|
||||
b.ToTable("EventRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.GuildConfig", b =>
|
||||
{
|
||||
b.Property<ulong>("GuildId")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||
|
||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||
|
||||
b.Property<ulong>("ParticipantRoleId");
|
||||
|
||||
b.Property<string>("Prefix");
|
||||
|
||||
b.HasKey("GuildId");
|
||||
|
||||
b.ToTable("GuildConfigs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.Event", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.GuildConfig", "Guild")
|
||||
.WithMany("Events")
|
||||
.HasForeignKey("GuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventParticipant", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.Event", "Event")
|
||||
.WithMany("Participants")
|
||||
.HasForeignKey("EventId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("EventBot.Entities.EventRole", "Role")
|
||||
.WithMany("Participants")
|
||||
.HasForeignKey("EventRoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventRole", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.Event", "Event")
|
||||
.WithMany("Roles")
|
||||
.HasForeignKey("EventId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace EventBot.Migrations.MySql
|
||||
{
|
||||
public partial class AutoRolesAndChannels : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "AutoRoleChannelCategoryId",
|
||||
table: "GuildConfigs",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "ChannelId",
|
||||
table: "EventRoles",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "RoleId",
|
||||
table: "EventRoles",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AutoRoleChannelCategoryId",
|
||||
table: "GuildConfigs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ChannelId",
|
||||
table: "EventRoles");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RoleId",
|
||||
table: "EventRoles");
|
||||
}
|
||||
}
|
||||
}
|
@@ -72,8 +72,6 @@ namespace EventBot.Migrations.MySql
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("ChannelId");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<string>("Emote");
|
||||
@@ -82,8 +80,6 @@ namespace EventBot.Migrations.MySql
|
||||
|
||||
b.Property<int>("MaxParticipants");
|
||||
|
||||
b.Property<ulong>("RoleId");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.HasKey("Id");
|
||||
@@ -98,8 +94,6 @@ namespace EventBot.Migrations.MySql
|
||||
b.Property<ulong>("GuildId")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||
|
||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||
|
||||
b.Property<ulong>("ParticipantRoleId");
|
||||
|
@@ -1,146 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using EventBot.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace EventBot.Migrations.Sqlite
|
||||
{
|
||||
[DbContext(typeof(SqliteDatabaseService))]
|
||||
[Migration("20190620080021_AutoRolesAndChannels")]
|
||||
partial class AutoRolesAndChannels
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.Event", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<bool>("Active");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<ulong>("GuildId");
|
||||
|
||||
b.Property<ulong>("MessageChannelId");
|
||||
|
||||
b.Property<ulong>("MessageId");
|
||||
|
||||
b.Property<DateTime>("Opened");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.Property<int>("Type");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GuildId");
|
||||
|
||||
b.ToTable("Events");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventParticipant", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("EventId");
|
||||
|
||||
b.Property<int>("EventRoleId");
|
||||
|
||||
b.Property<string>("UserData");
|
||||
|
||||
b.Property<ulong>("UserId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EventId");
|
||||
|
||||
b.HasIndex("EventRoleId");
|
||||
|
||||
b.ToTable("EventParticipants");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventRole", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("ChannelId");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<string>("Emote");
|
||||
|
||||
b.Property<int>("EventId");
|
||||
|
||||
b.Property<int>("MaxParticipants");
|
||||
|
||||
b.Property<ulong>("RoleId");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EventId");
|
||||
|
||||
b.ToTable("EventRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.GuildConfig", b =>
|
||||
{
|
||||
b.Property<ulong>("GuildId")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||
|
||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||
|
||||
b.Property<ulong>("ParticipantRoleId");
|
||||
|
||||
b.Property<string>("Prefix");
|
||||
|
||||
b.HasKey("GuildId");
|
||||
|
||||
b.ToTable("GuildConfigs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.Event", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.GuildConfig", "Guild")
|
||||
.WithMany("Events")
|
||||
.HasForeignKey("GuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventParticipant", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.Event", "Event")
|
||||
.WithMany("Participants")
|
||||
.HasForeignKey("EventId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("EventBot.Entities.EventRole", "Role")
|
||||
.WithMany("Participants")
|
||||
.HasForeignKey("EventRoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EventBot.Entities.EventRole", b =>
|
||||
{
|
||||
b.HasOne("EventBot.Entities.Event", "Event")
|
||||
.WithMany("Roles")
|
||||
.HasForeignKey("EventId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace EventBot.Migrations.Sqlite
|
||||
{
|
||||
public partial class AutoRolesAndChannels : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "AutoRoleChannelCategoryId",
|
||||
table: "GuildConfigs",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "ChannelId",
|
||||
table: "EventRoles",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "RoleId",
|
||||
table: "EventRoles",
|
||||
nullable: false,
|
||||
defaultValue: 0ul);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AutoRoleChannelCategoryId",
|
||||
table: "GuildConfigs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ChannelId",
|
||||
table: "EventRoles");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RoleId",
|
||||
table: "EventRoles");
|
||||
}
|
||||
}
|
||||
}
|
@@ -71,8 +71,6 @@ namespace EventBot.Migrations.Sqlite
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("ChannelId");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<string>("Emote");
|
||||
@@ -81,8 +79,6 @@ namespace EventBot.Migrations.Sqlite
|
||||
|
||||
b.Property<int>("MaxParticipants");
|
||||
|
||||
b.Property<ulong>("RoleId");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.HasKey("Id");
|
||||
@@ -97,8 +93,6 @@ namespace EventBot.Migrations.Sqlite
|
||||
b.Property<ulong>("GuildId")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||
|
||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||
|
||||
b.Property<ulong>("ParticipantRoleId");
|
||||
|
@@ -1,47 +0,0 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace EventBot.Misc
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
|
||||
public static ContextType GetContextType(this ICommandContext context)
|
||||
{
|
||||
ContextType type = 0;
|
||||
if (context.Channel is IGuildChannel)
|
||||
type |= ContextType.Guild;
|
||||
if (context.Channel is IDMChannel)
|
||||
type |= ContextType.DM;
|
||||
if (context.Channel is IGroupChannel)
|
||||
type |= ContextType.Group;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static bool IsContextType(this ICommandContext context, ContextType type) => (context.GetContextType() & type) != 0;
|
||||
|
||||
public static string FormatCallHelpString(this CommandInfo command)
|
||||
{
|
||||
return $"{command.Aliases[0]} {string.Join(" ", command.Parameters.Select(p => p.FormatParameter()))}";
|
||||
}
|
||||
|
||||
public static string FormatParameter(this ParameterInfo p) => p.IsOptional ? $"[{p.Name}]" : $"<{p.Name}>";
|
||||
public static string FormatParameterType(this ParameterInfo p)
|
||||
{
|
||||
var @switch = new Dictionary<Type, Func<ParameterInfo, string>>()
|
||||
{
|
||||
{ typeof(int), (_) => "Number" },
|
||||
|
||||
};
|
||||
if (@switch.ContainsKey(p.Type))
|
||||
return @switch[p.Type](p);
|
||||
else
|
||||
return p.Type.Name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -7,8 +7,6 @@ using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using EventBot.Attributes;
|
||||
using EventBot.Services;
|
||||
using Discord.Addons.Interactive;
|
||||
using EventBot.Misc;
|
||||
|
||||
namespace EventBot.Modules
|
||||
{
|
||||
@@ -24,7 +22,6 @@ namespace EventBot.Modules
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Command("prefix")]
|
||||
[Name("Configure prefix")]
|
||||
[Summary("Gets prefix.")]
|
||||
public async Task PrefixCommand()
|
||||
{
|
||||
@@ -41,7 +38,6 @@ namespace EventBot.Modules
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Command("prefix")]
|
||||
[Name("Configure prefix")]
|
||||
[Summary("Sets prefix.")]
|
||||
public async Task PrefixCommand(
|
||||
[Summary("New prefix to set")] string newPrefix)
|
||||
@@ -54,9 +50,8 @@ namespace EventBot.Modules
|
||||
await ReplyAsync($"Prefix has been set to `{guildConfig.Prefix}`");
|
||||
}
|
||||
|
||||
|
||||
[Group("help")]
|
||||
public class HelpModule : InteractiveBase<SocketCommandContext>
|
||||
public class HelpModule : ModuleBase<SocketCommandContext>
|
||||
{
|
||||
|
||||
private readonly CommandService _commands;
|
||||
@@ -66,91 +61,23 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command]
|
||||
[Name("Help")]
|
||||
[Summary("Lists all commands with there descriptions.")]
|
||||
public async Task DefaultHelpAsync()
|
||||
{
|
||||
var pagedCommands = _commands.Commands
|
||||
.OrderBy(c => c.Aliases[0])
|
||||
.Where(c => c.Attributes
|
||||
.Select(a =>
|
||||
{
|
||||
switch (a)
|
||||
{
|
||||
case NoHelpAttribute _:
|
||||
return false;
|
||||
case RequireContextAttribute rc:
|
||||
return Context.IsContextType(rc.Contexts);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.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 / 15)
|
||||
.Select(g => g.Select(o => o.Command));
|
||||
|
||||
var pager = new PaginatedMessage()
|
||||
{
|
||||
Title = "Command list",
|
||||
Color = Color.DarkBlue,
|
||||
Pages = pagedCommands.Select(p => string.Join("\r\n", p.Select(c =>
|
||||
{
|
||||
if (c.MA)
|
||||
return $"`{c.CI.FormatCallHelpString()}` - **{c.CI.Name}**";
|
||||
else
|
||||
return $"`{c.A}` `↪`";
|
||||
}))),
|
||||
Options = new PaginatedAppearanceOptions()
|
||||
{
|
||||
Info = null,
|
||||
JumpDisplayOptions = JumpDisplayOptions.Never
|
||||
}
|
||||
};
|
||||
await PagedReplyAsync(pager);
|
||||
}
|
||||
|
||||
[Command]
|
||||
[Name("Help")]
|
||||
[Summary("Shows detailed info about command.")]
|
||||
public async Task DefaultHelpAsync([Summary("Command ")][Remainder] string commandAlias)
|
||||
{
|
||||
var command = _commands.Commands.Where(c => c.Aliases.Contains(commandAlias)).FirstOrDefault();
|
||||
if (command == null)
|
||||
throw new Exception("This command was not found.");
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle(command.Name)
|
||||
.WithDescription(command.Summary)
|
||||
.WithColor(Color.DarkTeal);
|
||||
embed.AddField("Module", command.Module.Name, true);
|
||||
if (command.Aliases.Count > 1)
|
||||
embed.AddField("Aliases", string.Join(", ", command.Aliases));
|
||||
if(command.Parameters.Count > 0)
|
||||
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());
|
||||
}
|
||||
|
||||
[Command("types")]
|
||||
[Name("Type help")]
|
||||
[Priority(1)]
|
||||
[Summary("Shows information about avaivable types for command paramters.")]
|
||||
[NoHelp]
|
||||
public async Task TypeHelp()
|
||||
.WithTitle("Command list")
|
||||
.WithColor(Color.DarkBlue)
|
||||
.WithCurrentTimestamp()
|
||||
.WithFields(_commands.Commands
|
||||
.Where(c => c.Attributes.Where(a => a is NoHelpAttribute || (a is RequireContextAttribute requireContext)).Count() == 0)
|
||||
.Select(c =>
|
||||
new EmbedFieldBuilder()
|
||||
{
|
||||
await ReplyAsync($"There are following avaivable types for command input: \r\n" +
|
||||
$"***String*** - The most basic text input, must be qouted if there is space inside. Ex: `\"This is a string\"`; `ThisCanBeUsedAlsoAsString`\r\n" +
|
||||
$"***Number*** - Just a simple number. Ex: `1`; `-2`; `1523`\r\n" +
|
||||
$"***User*** - Mention or ID of user. Ex: `360710685186850826`; `Skull132#1984`; {Context.Client.CurrentUser.Mention}\r\n" +
|
||||
$"***Event*** - ID of event. Just positive numbers 🙂.\r\n" +
|
||||
$"***EventRole*** - ID of event's role. Also positive numbers 😊.\r\n" +
|
||||
$"***EventParticipactionType*** - What type you want. Ex: `Quick`; `Detailed`");
|
||||
Name = $"`{string.Join(", ", c.Aliases)} {string.Join(" ", c.Parameters.Select(p => p.IsOptional ? $"[{p.Name}]" : $"<{p.Name}>"))}`",
|
||||
Value = c.Summary
|
||||
})
|
||||
);
|
||||
await Context.User.SendMessageAsync(embed: embed.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,12 +9,10 @@ using System.Linq;
|
||||
using EventBot.Entities;
|
||||
using Discord.WebSocket;
|
||||
using Discord.Addons.Interactive;
|
||||
using EventBot.Attributes;
|
||||
|
||||
namespace EventBot.Modules
|
||||
{
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Name("Event")]
|
||||
public class EventModule : ModuleBase<SocketCommandContext>
|
||||
{
|
||||
private readonly EventManagementService _events;
|
||||
@@ -26,13 +24,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("join")]
|
||||
[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(
|
||||
public async Task JoinAsync(
|
||||
[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,
|
||||
[Summary("Optional event ID, used to join an event that started before the most recent one.")] Event @event = null)
|
||||
@@ -60,8 +53,6 @@ namespace EventBot.Modules
|
||||
[RequireUserPermission(GuildPermission.Administrator, Group = "Permission")]
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[Group("event")]
|
||||
//[Alias("e")]
|
||||
[Name("Event management")]
|
||||
public class EventManagementModule : InteractiveBase<SocketCommandContext>
|
||||
{
|
||||
private readonly EventManagementService _events;
|
||||
@@ -72,11 +63,9 @@ namespace EventBot.Modules
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("config logchannel")]
|
||||
[Name("Configure logging channel")]
|
||||
[Summary("Sets logging channel for role changes.")]
|
||||
public async Task ConfigureEventLogChannel(
|
||||
public async Task SetRoleChannelAsync(
|
||||
[Summary("Channel to use for logging.")] IChannel channel)
|
||||
{
|
||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||
@@ -89,11 +78,9 @@ 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.")]
|
||||
public async Task ConfigureEventParticipantRole(
|
||||
public async Task SetParticipationRole(
|
||||
[Summary("Role to assign.")] IRole role)
|
||||
{
|
||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||
@@ -106,36 +93,9 @@ 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(
|
||||
public async Task NewEvent(
|
||||
[Summary("Title for the event.")] string title,
|
||||
[Summary("Description for the event.")] string description,
|
||||
[Summary("Type of event registration.")] Event.EventParticipactionType type = Event.EventParticipactionType.Quick)
|
||||
@@ -156,9 +116,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.")]
|
||||
public async Task UpdateEventTitle(
|
||||
[Summary("Title for the event.")] string title,
|
||||
@@ -175,10 +133,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")]
|
||||
[Summary("Updates the event's description.")]
|
||||
public async Task UpdateEventDescription(
|
||||
[Summary("Description for the event.")] string description,
|
||||
@@ -196,12 +151,8 @@ 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)
|
||||
@@ -223,14 +174,8 @@ 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,
|
||||
@@ -260,24 +205,13 @@ 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.")]
|
||||
[Summary("Updates the role's title")]
|
||||
public async Task UpdateEventRoleTitle(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
[Summary("The new title for the role.")][Remainder] string title)
|
||||
@@ -288,26 +222,19 @@ 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")]
|
||||
[Command("role update desc")]
|
||||
[Summary("Updates the role's description.")]
|
||||
public async Task UpdateEventRoleDescription(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
[Summary("New description for the role.")][Remainder] string description)
|
||||
{
|
||||
if (eventRole == null)
|
||||
throw new Exception("Please provide the correct role ID, this one does not exist.");
|
||||
throw new Exception("Please provide the correct role info, this one does not exist.");
|
||||
if (!eventRole.Event.Active)
|
||||
throw new Exception("This event is finalized. Please make a new event.");
|
||||
eventRole.Description = description;
|
||||
@@ -317,9 +244,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.")]
|
||||
public async Task UpdateEventRoleMaxParticipants(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
@@ -337,9 +262,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
|
||||
[Priority(2)]
|
||||
[Command("role update emote")]
|
||||
[Name("Update role's role")]
|
||||
[Summary("Updates a role's emote.")]
|
||||
public async Task UpdateEventRoleEmote(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
@@ -363,8 +286,6 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command()]
|
||||
[Alias("info")]
|
||||
[Name("Event info")]
|
||||
[Summary("Get info about event.")]
|
||||
public async Task EventInfo(
|
||||
[Summary("Event ID of event you wish to know more of.")] Event @event = null)
|
||||
@@ -393,37 +314,8 @@ 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")]
|
||||
[Name("Role info")]
|
||||
[Summary("Gets info about a role.")]
|
||||
public async Task EventRoleInfo(
|
||||
[Summary("Role you wish to have more info about.")] EventRole eventRole)
|
||||
@@ -446,10 +338,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
}
|
||||
|
||||
[Priority(1)]
|
||||
[Command("open")]
|
||||
[Alias("start", "begin")]
|
||||
[Name("Open event")]
|
||||
[Summary("Open registration for event here.")]
|
||||
public async Task EventOpen(
|
||||
[Summary("Event to open")] Event @event = null)
|
||||
@@ -481,11 +370,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Priority(1)]
|
||||
[Command("close")]
|
||||
[Alias("stop", "end")]
|
||||
[Name("Close event")]
|
||||
[Summary("Closes event registration.")]
|
||||
public async Task EventClose(
|
||||
[Summary("Event to close")] Event @event = null)
|
||||
@@ -502,14 +387,10 @@ namespace EventBot.Modules
|
||||
@event.MessageId = 0;
|
||||
@event.MessageChannelId = 0;
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"Event's `{@event.Id}` registration has been closed, its registration message will now be normal message.");
|
||||
await ReplyAsync($"Event `{@event.Id}`'s registration has been closed, its registration message will now be normal message.");
|
||||
}
|
||||
|
||||
|
||||
[Priority(1)]
|
||||
[Command("finalize")]
|
||||
[Alias("archive")]
|
||||
[Name("Archive event")]
|
||||
[Summary("Archives event and reverts all role additions. This is irreversable.")]
|
||||
public async Task EventFinilize(
|
||||
[Summary("Event to finilize")] Event @event = null)
|
||||
@@ -524,34 +405,23 @@ namespace EventBot.Modules
|
||||
@event.Active = false;
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
await ReplyAsync($"Event `{@event.Id}` has been finalized. Removing participant roles..");
|
||||
await ReplyAsync($"Event `{@event.Id}`'s has been finalized. Removing participant roles..");
|
||||
if (@event.Guild.ParticipantRoleId != 0)
|
||||
foreach (var participant in @event.Participants)
|
||||
{
|
||||
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")]
|
||||
[Summary("Lists all prevous events that took on this server.")]
|
||||
public async Task EventArchive()
|
||||
{
|
||||
var guildEvents = _database.Events.Where(e => e.GuildId == Context.Guild.Id).OrderBy(e => e.Opened).ToList();
|
||||
if (guildEvents.Count() == 0)
|
||||
throw new Exception("There are no events that have been run on this server.");
|
||||
throw new Exception("No events have been run on this server.");
|
||||
|
||||
var pagedEvents = guildEvents
|
||||
.Select((e, i) => new { Event = e, Index = i })
|
||||
@@ -577,14 +447,8 @@ namespace EventBot.Modules
|
||||
await PagedReplyAsync(pager);
|
||||
}
|
||||
|
||||
|
||||
[Priority(2)]
|
||||
[Command("participant add")]
|
||||
[Name("Add participant")]
|
||||
[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")]
|
||||
[Summary("Add user to event role. Acts like join command.")]
|
||||
public async Task EventParticipantAdd(
|
||||
[Summary("User ID or discord mention.")] IUser user,
|
||||
[Summary("Role emote or role ID to join.")] string emoteOrId,
|
||||
@@ -611,13 +475,10 @@ namespace EventBot.Modules
|
||||
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
||||
}
|
||||
|
||||
[Priority(2)]
|
||||
[Command("participant remove")]
|
||||
[Alias("participant delete")]
|
||||
[Name("Remove participant")]
|
||||
[Summary("Remove participant from event role.")]
|
||||
public async Task EventParticipantRemove(
|
||||
[Summary("User that is participating's ID or discord mention.")] IUser user,
|
||||
[Summary("User that is participanting's ID or discord mention.")] IUser user,
|
||||
[Summary("Event to remove the participant from.")] Event @event = null)
|
||||
{
|
||||
if (@event == null)
|
||||
@@ -626,15 +487,25 @@ 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) || !(Context.User is IGuildUser initiator))
|
||||
|
||||
if (!(user is IGuildUser guildUser))
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,10 @@ namespace EventBot
|
||||
private ServiceProvider ConfigureServices()
|
||||
{
|
||||
return new ServiceCollection()
|
||||
.AddSingleton(s => new DiscordSocketClient(getDiscordSocketConfig()))
|
||||
.AddSingleton(s => new DiscordSocketClient(new DiscordSocketConfig() {
|
||||
LogLevel = LogSeverity.Debug,
|
||||
MessageCacheSize = 1500
|
||||
}))
|
||||
.AddSingleton<CommandService>()
|
||||
.AddSingleton<CommandHandlingService>()
|
||||
.AddSingleton<EventManagementService>()
|
||||
@@ -64,19 +67,5 @@ namespace EventBot
|
||||
//.AddSingleton<PictureService>()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
|
||||
private DiscordSocketConfig getDiscordSocketConfig()
|
||||
{
|
||||
var config = new DiscordSocketConfig()
|
||||
{
|
||||
MessageCacheSize = 1500
|
||||
};
|
||||
#if DEBUG
|
||||
config.LogLevel = LogSeverity.Debug;
|
||||
#endif
|
||||
if(Environment.GetEnvironmentVariable("DEBUG") != null)
|
||||
config.LogLevel = LogSeverity.Debug;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
"EventBot": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"dbconnection": "Server=server;Database=eventbot;User=eventbot;Password=password;",
|
||||
"token": "token here"
|
||||
"dbconnection": "Server=localhost;Database=eventbot;User=root;Password=tux;",
|
||||
"token": "<insert Token here>"
|
||||
}
|
||||
},
|
||||
"Docker": {
|
||||
|
@@ -58,7 +58,7 @@ namespace EventBot.Services
|
||||
var context = new SocketCommandContext(_discord, message);
|
||||
GuildConfig guildConfig = context.Guild != null ? _database.GuildConfigs.FirstOrDefault(g => g.GuildId == context.Guild.Id) : null;
|
||||
if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos))
|
||||
if (guildConfig != null && string.IsNullOrEmpty(guildConfig.Prefix))
|
||||
if (guildConfig != null)
|
||||
{
|
||||
if (!message.HasStringPrefix(guildConfig.Prefix, ref argPos))
|
||||
return;
|
||||
|
@@ -35,7 +35,6 @@ namespace EventBot.Services
|
||||
|
||||
_discord = services.GetRequiredService<DiscordSocketClient>();
|
||||
_discord.GuildAvailable += OnGuildAvaivable;
|
||||
_discord.JoinedGuild += OnGuildAvaivable;
|
||||
}
|
||||
public DatabaseService(): base() {}
|
||||
|
||||
|
@@ -25,28 +25,6 @@ namespace EventBot.Services
|
||||
|
||||
_discord.ReactionAdded += ReactionAddedAsync;
|
||||
_discord.MessageDeleted += MessageDeletedAsync;
|
||||
_discord.ChannelDestroyed += ChannelDeleted;
|
||||
_discord.RoleDeleted += RoleDeleted;
|
||||
}
|
||||
|
||||
private async Task RoleDeleted(SocketRole role)
|
||||
{
|
||||
var eventRole = _database.EventRoles.FirstOrDefault(r => r.RoleId == role.Id);
|
||||
if(eventRole != null)
|
||||
{
|
||||
eventRole.ChannelId = 0;
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ChannelDeleted(SocketChannel channel)
|
||||
{
|
||||
var eventRole = _database.EventRoles.FirstOrDefault(r => r.ChannelId == channel.Id);
|
||||
if (eventRole != null)
|
||||
{
|
||||
eventRole.ChannelId = 0;
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task TryJoinEvent(IGuildUser user, EventRole er, string extra, bool extraChecks = true)
|
||||
@@ -55,15 +33,13 @@ namespace EventBot.Services
|
||||
throw new Exception("Cross server events are forbidden.");
|
||||
if (extraChecks && er.ReamainingOpenings <= 0)
|
||||
throw new Exception("No openings are left.");
|
||||
if(er.Event.ParticipantCount > 0 && er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
||||
if(er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
||||
throw new Exception("You are already participating.");
|
||||
if(extraChecks && !er.Event.Active)
|
||||
throw new Exception("Event is closed.");
|
||||
|
||||
if (er.Event.Guild.ParticipantRoleId != 0)
|
||||
await user.AddRoleAsync(user.Guild.GetRole(er.Event.Guild.ParticipantRoleId));
|
||||
if (er.RoleId != 0)
|
||||
await user.AddRoleAsync(user.Guild.GetRole(er.RoleId));
|
||||
|
||||
var ep = new EventParticipant()
|
||||
{
|
||||
@@ -87,42 +63,6 @@ namespace EventBot.Services
|
||||
await (await user.Guild.GetTextChannelAsync(er.Event.Guild.EventRoleConfirmationChannelId)).SendMessageAsync(embed: embed.Build());
|
||||
}
|
||||
|
||||
public async Task RemoveParticipant(IGuildUser user, Event @event, IGuildUser initiator)
|
||||
{
|
||||
var participant = @event.Participants.FirstOrDefault(p => p.UserId == user.Id);
|
||||
_database.Remove(participant);
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle($"{user} been removed from event `{@event.Title}`, by {initiator}.")
|
||||
.WithDescription($"Their role was: `{participant.Role.Title}`")
|
||||
.WithColor(Color.Red);
|
||||
if (participant.UserData != null)
|
||||
embed.AddField("Provided details", $"`{participant.UserData}`");
|
||||
if (@event.Guild.EventRoleConfirmationChannelId != 0)
|
||||
await (await user.Guild.GetTextChannelAsync(@event.Guild.EventRoleConfirmationChannelId)).SendMessageAsync(embed: embed.Build());
|
||||
if (@event.Guild.ParticipantRoleId != 0)
|
||||
await user.RemoveRoleAsync(user.Guild.GetRole(@event.Guild.ParticipantRoleId));
|
||||
if (participant.Role.RoleId != 0)
|
||||
await user.RemoveRoleAsync(user.Guild.GetRole(participant.Role.RoleId));
|
||||
}
|
||||
|
||||
public async Task RemoveParticipant(EventParticipant participant, IGuildUser initiator)
|
||||
{
|
||||
IGuildUser user = await initiator.Guild.GetUserAsync(participant.UserId);
|
||||
_database.Remove(participant);
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle($"{user} been removed from event `{participant.Event.Title}`, by {initiator}.")
|
||||
.WithDescription($"Their role was: `{participant.Role.Title}`")
|
||||
.WithColor(Color.Red);
|
||||
if (participant.UserData != null)
|
||||
embed.AddField("Provided details", $"`{participant.UserData}`");
|
||||
if (participant.Event.Guild.EventRoleConfirmationChannelId != 0)
|
||||
await (await user.Guild.GetTextChannelAsync(participant.Event.Guild.EventRoleConfirmationChannelId)).SendMessageAsync(embed: embed.Build());
|
||||
if (participant.Event.Guild.ParticipantRoleId != 0)
|
||||
await user.RemoveRoleAsync(user.Guild.GetRole(participant.Event.Guild.ParticipantRoleId));
|
||||
}
|
||||
|
||||
public async Task RemoveParticipant(IGuildUser user, EventRole eventRole, IGuildUser initiator) => await RemoveParticipant(user, eventRole.Event, initiator);
|
||||
|
||||
public Event FindEventBy(IGuild guild, bool bypassActive = false)
|
||||
{
|
||||
return _database.Events.OrderByDescending(e => e.Opened).FirstOrDefault(e => e.GuildId == guild.Id && (e.Active || bypassActive));
|
||||
|
@@ -8,7 +8,6 @@ This is environment variable for Mysql / MariaDb database connection. Example co
|
||||
|
||||
```Server=localhost,123;Database=eventbot;User=root;Password=password;```
|
||||
|
||||
## Making migrations
|
||||
|
||||
`Add-Migration InitialDatabase -Context MySqlDatabaseService -OutputDir Migrations\MySql`
|
||||
`Add-Migration InitialDatabase -Context SqliteDatabaseService -OutputDir Migrations\Sqlite`
|
Reference in New Issue
Block a user