Compare commits
21 Commits
e43cd71a7d
...
debug_bran
Author | SHA1 | Date | |
---|---|---|---|
|
ed86405263 | ||
|
203811366b | ||
|
e9f59780ed | ||
|
18657d7fab | ||
|
b5702faa31 | ||
|
9ac6343406 | ||
|
c28ffe2ade | ||
|
92459fb4de | ||
|
32246855fa | ||
|
941716b19d | ||
|
9ede67c61b | ||
|
021c497288 | ||
|
5d32d3b611 | ||
|
17e08c6f01 | ||
|
6ce26b1d39 | ||
|
05143db059 | ||
|
0522482685 | ||
|
e1f376f92c | ||
|
f73d84803e | ||
|
2a80032cae | ||
|
cea06e205c |
10
.travis.yml
Normal file
10
.travis.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
language: csharp
|
||||||
|
mono: none
|
||||||
|
dist: xenial
|
||||||
|
dotnet: 2.2
|
||||||
|
|
||||||
|
install:
|
||||||
|
- dotnet restore
|
||||||
|
|
||||||
|
script:
|
||||||
|
- dotnet build
|
16
EventBot/Attributes/ExampleAttribute.cs
Normal file
16
EventBot/Attributes/ExampleAttribute.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -7,10 +7,10 @@ COPY ["EventBot/EventBot.csproj", "EventBot/"]
|
|||||||
RUN dotnet restore "EventBot/EventBot.csproj"
|
RUN dotnet restore "EventBot/EventBot.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/EventBot"
|
WORKDIR "/src/EventBot"
|
||||||
RUN dotnet build "EventBot.csproj" -c Release -o /app
|
RUN dotnet build "EventBot.csproj" -c Debug -o /app
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
RUN dotnet publish "EventBot.csproj" -c Release -o /app
|
RUN dotnet publish "EventBot.csproj" -c Debug -o /app
|
||||||
|
|
||||||
FROM base AS final
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace EventBot.Entities
|
namespace EventBot.Entities
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,8 @@ namespace EventBot.Entities
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string Emote { get; set; }
|
public string Emote { get; set; }
|
||||||
public int MaxParticipants { get; set; }
|
public int MaxParticipants { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
public ulong RoleId { get; set; }
|
||||||
public int EventId { get; set; }
|
public int EventId { get; set; }
|
||||||
[ForeignKey("EventId")]
|
[ForeignKey("EventId")]
|
||||||
public virtual Event Event { get; set; }
|
public virtual Event Event { get; set; }
|
||||||
@@ -22,6 +25,8 @@ namespace EventBot.Entities
|
|||||||
public int ParticipantCount => Participants == null ? 0 : Participants.Count;
|
public int ParticipantCount => Participants == null ? 0 : Participants.Count;
|
||||||
public int ReamainingOpenings => MaxParticipants < 0 ? 1 : MaxParticipants - ParticipantCount;
|
public int ReamainingOpenings => MaxParticipants < 0 ? 1 : MaxParticipants - ParticipantCount;
|
||||||
|
|
||||||
|
public string ChannelName => Regex.Replace(Title.Replace(' ', '-'), "(?!\\w)", "");
|
||||||
|
|
||||||
public int SortNumber
|
public int SortNumber
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@@ -12,6 +12,7 @@ namespace EventBot.Entities
|
|||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
public ulong EventRoleConfirmationChannelId { get; set; }
|
public ulong EventRoleConfirmationChannelId { get; set; }
|
||||||
public ulong ParticipantRoleId { get; set; }
|
public ulong ParticipantRoleId { get; set; }
|
||||||
|
public ulong AutoRoleChannelCategoryId { get; set; }
|
||||||
public virtual ICollection<Event> Events { get; set; }
|
public virtual ICollection<Event> Events { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,15 +9,15 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Addons.Interactive" Version="1.0.1" />
|
<PackageReference Include="Discord.Addons.Interactive" Version="1.0.1" />
|
||||||
<PackageReference Include="Discord.Net" Version="2.1.1" />
|
<PackageReference Include="Discord.Net" Version="2.1.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.design" Version="2.2.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.design" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
147
EventBot/Migrations/MySql/20190620075923_AutoRolesAndChannels.Designer.cs
generated
Normal file
147
EventBot/Migrations/MySql/20190620075923_AutoRolesAndChannels.Designer.cs
generated
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
// <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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
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,6 +72,8 @@ namespace EventBot.Migrations.MySql
|
|||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
b.Property<string>("Description");
|
b.Property<string>("Description");
|
||||||
|
|
||||||
b.Property<string>("Emote");
|
b.Property<string>("Emote");
|
||||||
@@ -80,6 +82,8 @@ namespace EventBot.Migrations.MySql
|
|||||||
|
|
||||||
b.Property<int>("MaxParticipants");
|
b.Property<int>("MaxParticipants");
|
||||||
|
|
||||||
|
b.Property<ulong>("RoleId");
|
||||||
|
|
||||||
b.Property<string>("Title");
|
b.Property<string>("Title");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@@ -94,6 +98,8 @@ namespace EventBot.Migrations.MySql
|
|||||||
b.Property<ulong>("GuildId")
|
b.Property<ulong>("GuildId")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||||
|
|
||||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("ParticipantRoleId");
|
b.Property<ulong>("ParticipantRoleId");
|
||||||
|
146
EventBot/Migrations/Sqlite/20190620080021_AutoRolesAndChannels.Designer.cs
generated
Normal file
146
EventBot/Migrations/Sqlite/20190620080021_AutoRolesAndChannels.Designer.cs
generated
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
// <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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
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,6 +71,8 @@ namespace EventBot.Migrations.Sqlite
|
|||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
b.Property<string>("Description");
|
b.Property<string>("Description");
|
||||||
|
|
||||||
b.Property<string>("Emote");
|
b.Property<string>("Emote");
|
||||||
@@ -79,6 +81,8 @@ namespace EventBot.Migrations.Sqlite
|
|||||||
|
|
||||||
b.Property<int>("MaxParticipants");
|
b.Property<int>("MaxParticipants");
|
||||||
|
|
||||||
|
b.Property<ulong>("RoleId");
|
||||||
|
|
||||||
b.Property<string>("Title");
|
b.Property<string>("Title");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@@ -93,6 +97,8 @@ namespace EventBot.Migrations.Sqlite
|
|||||||
b.Property<ulong>("GuildId")
|
b.Property<ulong>("GuildId")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("AutoRoleChannelCategoryId");
|
||||||
|
|
||||||
b.Property<ulong>("EventRoleConfirmationChannelId");
|
b.Property<ulong>("EventRoleConfirmationChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("ParticipantRoleId");
|
b.Property<ulong>("ParticipantRoleId");
|
||||||
|
@@ -15,16 +15,16 @@ namespace EventBot.Misc
|
|||||||
{
|
{
|
||||||
var database = services.GetRequiredService<DatabaseService>();
|
var database = services.GetRequiredService<DatabaseService>();
|
||||||
if (context.Guild == null)
|
if (context.Guild == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Event roles are avaivable only inside guild context."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Event roles are available only inside a discord server."));
|
||||||
EventRole er = null;
|
EventRole er = null;
|
||||||
if (int.TryParse(input, out int id))
|
if (int.TryParse(input, out int id))
|
||||||
er = database.EventRoles.FirstOrDefault(r => r.Id == id);
|
er = database.EventRoles.FirstOrDefault(r => r.Id == id);
|
||||||
else
|
else
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event role id is not a valid number."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event role ID is not a valid number."));
|
||||||
if(er == null)
|
if(er == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Specified event role was not found."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Specified event role was not found."));
|
||||||
if(er.Event?.GuildId != context.Guild.Id)
|
if(er.Event?.GuildId != context.Guild.Id)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, "Cross guild event role access is denied."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, "Cross server event role access is denied."));
|
||||||
return Task.FromResult(TypeReaderResult.FromSuccess(er));
|
return Task.FromResult(TypeReaderResult.FromSuccess(er));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,14 @@ namespace EventBot.Misc
|
|||||||
{
|
{
|
||||||
var events = services.GetRequiredService<EventManagementService>();
|
var events = services.GetRequiredService<EventManagementService>();
|
||||||
if (context.Guild == null)
|
if (context.Guild == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Events are avaivable only inside guild context."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Events are available only inside a discord server."));
|
||||||
Event ev;
|
Event ev;
|
||||||
if (input == null)
|
if (input == null)
|
||||||
ev = events.FindEventBy(context.Guild, true);
|
ev = events.FindEventBy(context.Guild, true);
|
||||||
else if (int.TryParse(input, out int id))
|
else if (int.TryParse(input, out int id))
|
||||||
ev = events.FindEventBy(context.Guild, id, true);
|
ev = events.FindEventBy(context.Guild, id, true);
|
||||||
else
|
else
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event id is not a number."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event ID is not a number."));
|
||||||
|
|
||||||
return Task.FromResult(TypeReaderResult.FromSuccess(ev));
|
return Task.FromResult(TypeReaderResult.FromSuccess(ev));
|
||||||
}
|
}
|
||||||
|
47
EventBot/Misc/Extensions.cs
Normal file
47
EventBot/Misc/Extensions.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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,6 +7,8 @@ using System.Threading.Tasks;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using EventBot.Attributes;
|
using EventBot.Attributes;
|
||||||
using EventBot.Services;
|
using EventBot.Services;
|
||||||
|
using Discord.Addons.Interactive;
|
||||||
|
using EventBot.Misc;
|
||||||
|
|
||||||
namespace EventBot.Modules
|
namespace EventBot.Modules
|
||||||
{
|
{
|
||||||
@@ -22,6 +24,7 @@ namespace EventBot.Modules
|
|||||||
[RequireOwner(Group = "Permission")]
|
[RequireOwner(Group = "Permission")]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[Command("prefix")]
|
[Command("prefix")]
|
||||||
|
[Name("Configure prefix")]
|
||||||
[Summary("Gets prefix.")]
|
[Summary("Gets prefix.")]
|
||||||
public async Task PrefixCommand()
|
public async Task PrefixCommand()
|
||||||
{
|
{
|
||||||
@@ -38,6 +41,7 @@ namespace EventBot.Modules
|
|||||||
[RequireOwner(Group = "Permission")]
|
[RequireOwner(Group = "Permission")]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[Command("prefix")]
|
[Command("prefix")]
|
||||||
|
[Name("Configure prefix")]
|
||||||
[Summary("Sets prefix.")]
|
[Summary("Sets prefix.")]
|
||||||
public async Task PrefixCommand(
|
public async Task PrefixCommand(
|
||||||
[Summary("New prefix to set")] string newPrefix)
|
[Summary("New prefix to set")] string newPrefix)
|
||||||
@@ -50,8 +54,9 @@ namespace EventBot.Modules
|
|||||||
await ReplyAsync($"Prefix has been set to `{guildConfig.Prefix}`");
|
await ReplyAsync($"Prefix has been set to `{guildConfig.Prefix}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Group("help")]
|
[Group("help")]
|
||||||
public class HelpModule : ModuleBase<SocketCommandContext>
|
public class HelpModule : InteractiveBase<SocketCommandContext>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly CommandService _commands;
|
private readonly CommandService _commands;
|
||||||
@@ -61,23 +66,91 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
|
[Name("Help")]
|
||||||
[Summary("Lists all commands with there descriptions.")]
|
[Summary("Lists all commands with there descriptions.")]
|
||||||
public async Task DefaultHelpAsync()
|
public async Task DefaultHelpAsync()
|
||||||
{
|
{
|
||||||
var embed = new EmbedBuilder()
|
var pagedCommands = _commands.Commands
|
||||||
.WithTitle("Command list")
|
.OrderBy(c => c.Aliases[0])
|
||||||
.WithColor(Color.DarkBlue)
|
.Where(c => c.Attributes
|
||||||
.WithCurrentTimestamp()
|
.Select(a =>
|
||||||
.WithFields(_commands.Commands
|
{
|
||||||
.Where(c => c.Attributes.Where(a => a is NoHelpAttribute || (a is RequireContextAttribute requireContext)).Count() == 0)
|
switch (a)
|
||||||
.Select(c =>
|
|
||||||
new EmbedFieldBuilder()
|
|
||||||
{
|
{
|
||||||
Name = $"`{string.Join(", ", c.Aliases)} {string.Join(" ", c.Parameters.Select(p => p.IsOptional ? $"[{p.Name}]" : $"<{p.Name}>"))}`",
|
case NoHelpAttribute _:
|
||||||
Value = c.Summary
|
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._" : "")}" ))
|
||||||
);
|
);
|
||||||
await Context.User.SendMessageAsync(embed: embed.Build());
|
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()
|
||||||
|
{
|
||||||
|
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`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,10 +9,12 @@ using System.Linq;
|
|||||||
using EventBot.Entities;
|
using EventBot.Entities;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Discord.Addons.Interactive;
|
using Discord.Addons.Interactive;
|
||||||
|
using EventBot.Attributes;
|
||||||
|
|
||||||
namespace EventBot.Modules
|
namespace EventBot.Modules
|
||||||
{
|
{
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[Name("Event")]
|
||||||
public class EventModule : ModuleBase<SocketCommandContext>
|
public class EventModule : ModuleBase<SocketCommandContext>
|
||||||
{
|
{
|
||||||
private readonly EventManagementService _events;
|
private readonly EventManagementService _events;
|
||||||
@@ -24,27 +26,32 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command("join")]
|
[Command("join")]
|
||||||
|
[Alias("j")]
|
||||||
|
[Name("Join event")]
|
||||||
[Summary("Joins latest or specified event with specified event role.")]
|
[Summary("Joins latest or specified event with specified event role.")]
|
||||||
public async Task JoinAsync(
|
[Example("join :slight_smile:")]
|
||||||
[Summary("Role emote or role id to join.")] string emoteOrId,
|
[Example("join 5 \"John Smith\"")]
|
||||||
[Summary("Extra information that migth be needed by organizers.")] string extraInformation = null,
|
[Example("join :gun: \"Tpr. James\" 2")]
|
||||||
[Summary("Optional event ID for joining event that is not most recent one.")] Event @event = null)
|
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,
|
||||||
|
[Summary("Optional event ID, used to join an event that started before the most recent one.")] Event @event = null)
|
||||||
{
|
{
|
||||||
EventRole er;
|
EventRole er;
|
||||||
if (!(Context.User is SocketGuildUser guildUser))
|
if (!(Context.User is SocketGuildUser guildUser))
|
||||||
throw new Exception("This command must be executed inside guild.");
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null & !(int.TryParse(emoteOrId, out int roleId)))
|
if (@event == null & !(int.TryParse(emoteOrId, out int roleId)))
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
else if (@event == null)
|
else if (@event == null)
|
||||||
er = _database.EventRoles.FirstOrDefault(r => r.Id == roleId);
|
er = _database.EventRoles.FirstOrDefault(r => r.Id == roleId);
|
||||||
else
|
else
|
||||||
er = @event.Roles.FirstOrDefault(r => r.Emote == emoteOrId);
|
er = @event.Roles.FirstOrDefault(r => r.Emote == emoteOrId);
|
||||||
if (er == null)
|
if (er == null)
|
||||||
throw new ArgumentException("Invalid emote or event id specified");
|
throw new ArgumentException("Invalid emote or event ID specified.");
|
||||||
if (@event.MessageId == 0)
|
if (@event.MessageId == 0)
|
||||||
throw new Exception("You can't join not opened event.");
|
throw new Exception("You cannot join an event that hasn't been opened!");
|
||||||
|
|
||||||
await _events.TryJoinEvent(guildUser, er, extraInformation);
|
await _events.TryJoinEvent(guildUser, er, extraInformation);
|
||||||
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
||||||
@@ -53,6 +60,8 @@ namespace EventBot.Modules
|
|||||||
[RequireUserPermission(GuildPermission.Administrator, Group = "Permission")]
|
[RequireUserPermission(GuildPermission.Administrator, Group = "Permission")]
|
||||||
[RequireOwner(Group = "Permission")]
|
[RequireOwner(Group = "Permission")]
|
||||||
[Group("event")]
|
[Group("event")]
|
||||||
|
//[Alias("e")]
|
||||||
|
[Name("Event management")]
|
||||||
public class EventManagementModule : InteractiveBase<SocketCommandContext>
|
public class EventManagementModule : InteractiveBase<SocketCommandContext>
|
||||||
{
|
{
|
||||||
private readonly EventManagementService _events;
|
private readonly EventManagementService _events;
|
||||||
@@ -63,14 +72,16 @@ namespace EventBot.Modules
|
|||||||
_database = database;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("config logchannel")]
|
[Command("config logchannel")]
|
||||||
|
[Name("Configure logging channel")]
|
||||||
[Summary("Sets logging channel for role changes.")]
|
[Summary("Sets logging channel for role changes.")]
|
||||||
public async Task SetRoleChannelAsync(
|
public async Task ConfigureEventLogChannel(
|
||||||
[Summary("Channel to use for logging.")] IChannel channel)
|
[Summary("Channel to use for logging.")] IChannel channel)
|
||||||
{
|
{
|
||||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||||
if (guild == null)
|
if (guild == null)
|
||||||
throw new Exception("This command must be executed inside guild.");
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
|
|
||||||
guild.EventRoleConfirmationChannelId = channel.Id;
|
guild.EventRoleConfirmationChannelId = channel.Id;
|
||||||
var s = _database.SaveChangesAsync();
|
var s = _database.SaveChangesAsync();
|
||||||
@@ -78,14 +89,16 @@ namespace EventBot.Modules
|
|||||||
await s;
|
await s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("config partrole")]
|
[Command("config partrole")]
|
||||||
[Summary("Sets role to assign when they selelct role.")]
|
[Name("Configure participant role")]
|
||||||
public async Task SetParticipationRole(
|
[Summary("Sets discord role to assign when the user selects a role.")]
|
||||||
|
public async Task ConfigureEventParticipantRole(
|
||||||
[Summary("Role to assign.")] IRole role)
|
[Summary("Role to assign.")] IRole role)
|
||||||
{
|
{
|
||||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||||
if (guild == null)
|
if (guild == null)
|
||||||
throw new Exception("This command must be executed inside guild.");
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
|
|
||||||
guild.ParticipantRoleId = role.Id;
|
guild.ParticipantRoleId = role.Id;
|
||||||
var s = _database.SaveChangesAsync();
|
var s = _database.SaveChangesAsync();
|
||||||
@@ -93,16 +106,43 @@ namespace EventBot.Modules
|
|||||||
await s;
|
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")]
|
[Command("new")]
|
||||||
[Summary("Creates new event.")]
|
[Alias("add", "create")]
|
||||||
public async Task NewEvent(
|
[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("Title for the event.")] string title,
|
||||||
[Summary("Description for the event.")] string description,
|
[Summary("Description for the event.")] string description,
|
||||||
[Summary("Type of event registration.")] Event.EventParticipactionType type = Event.EventParticipactionType.Quick)
|
[Summary("Type of event registration.")] Event.EventParticipactionType type = Event.EventParticipactionType.Quick)
|
||||||
{
|
{
|
||||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||||
if (guild == null)
|
if (guild == null)
|
||||||
throw new Exception("This command must be executed inside guild.");
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
var @event = new Event()
|
var @event = new Event()
|
||||||
{
|
{
|
||||||
Title = title,
|
Title = title,
|
||||||
@@ -113,11 +153,13 @@ namespace EventBot.Modules
|
|||||||
|
|
||||||
_database.Add(@event);
|
_database.Add(@event);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Created new {@event.Type} event `{title}`, with description of `{description}`. It's ID is `{@event.Id}`.");
|
await ReplyAsync($"Created new {@event.Type} event `{title}`, with description: `{description}`. Its ID is `{@event.Id}`.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("update title")]
|
[Command("update title")]
|
||||||
[Summary("Updates event title.")]
|
[Name("Update event's title")]
|
||||||
|
[Summary("Updates the event's title.")]
|
||||||
public async Task UpdateEventTitle(
|
public async Task UpdateEventTitle(
|
||||||
[Summary("Title for the event.")] string title,
|
[Summary("Title for the event.")] string title,
|
||||||
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
||||||
@@ -125,16 +167,19 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
@event.Title = title;
|
@event.Title = title;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Updated event(`{@event.Id}`) title to `{@event.Title}`");
|
await ReplyAsync($"Updated event's (`{@event.Id}`) title to `{@event.Title}`");
|
||||||
await _events.UpdateEventMessage(@event);
|
await _events.UpdateEventMessage(@event);
|
||||||
}
|
}
|
||||||
|
[Priority(2)]
|
||||||
[Command("update description")]
|
[Command("update description")]
|
||||||
[Summary("Updates event description.")]
|
[Alias("update desc")]
|
||||||
|
[Name("Update event's description")]
|
||||||
|
[Summary("Updates the event's description.")]
|
||||||
public async Task UpdateEventDescription(
|
public async Task UpdateEventDescription(
|
||||||
[Summary("Description for the event.")] string description,
|
[Summary("Description for the event.")] string description,
|
||||||
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
||||||
@@ -142,17 +187,21 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
@event.Description = description;
|
@event.Description = description;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Updated event(`{@event.Id}`) description to `{@event.Description}`");
|
await ReplyAsync($"Updated event's (`{@event.Id}`) description to `{@event.Description}`");
|
||||||
await _events.UpdateEventMessage(@event);
|
await _events.UpdateEventMessage(@event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("update type")]
|
[Command("update type")]
|
||||||
[Summary("Updates event 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(
|
public async Task UpdateEventType(
|
||||||
[Summary("Type of event registration.")] Event.EventParticipactionType type,
|
[Summary("Type of event registration.")] Event.EventParticipactionType type,
|
||||||
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
[Summary("Event to update, if not specified, updates latest event.")] Event @event = null)
|
||||||
@@ -162,11 +211,11 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
if (@event.MessageId != 0 && @event.Type != type)
|
if (@event.MessageId != 0 && @event.Type != type)
|
||||||
throw new Exception("Can't change event registration type when it's open for registration. Maube you meant to set type to `Unspecified` (-1)");
|
throw new Exception("Can't change event registration type when it's open for registration. Maybe you meant to set type to `Unspecified` (-1)");
|
||||||
if(@event.Type != type)
|
if(@event.Type != type)
|
||||||
@event.Type = type;
|
@event.Type = type;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
@@ -174,25 +223,31 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("role new")]
|
[Command("role new")]
|
||||||
[Summary("Adds new role to the event.")]
|
[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(
|
public async Task NewEventRole(
|
||||||
[Summary("Title for the role.")] string title,
|
[Summary("Title of the role.")] string title,
|
||||||
[Summary("Description for the role.")] string description,
|
[Summary("Description of the role.")] string description,
|
||||||
[Summary("Emote for the role.")] string emote,
|
[Summary("Emote for the role.")] string emote,
|
||||||
[Summary("Max openings, if number is negative, opening count is unlimited.")] int maxOpenings = -1,
|
[Summary("Max openings, if number is negative, opening count is unlimited.")] int maxOpenings = -1,
|
||||||
[Summary("Event to that role is meant for.")] Event @event = null)
|
[Summary("Which event to assign the role to.")] Event @event = null)
|
||||||
{
|
{
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
if (@event.Roles != null && @event.Roles.Count >= 20)
|
if (@event.Roles != null && @event.Roles.Count >= 20)
|
||||||
throw new Exception("There are too many roles for this event.");
|
throw new Exception("There are too many roles for this event.");
|
||||||
if(@event.MessageId != 0)
|
if(@event.MessageId != 0)
|
||||||
throw new Exception("Can't add new roles to event with open reigstration.");
|
throw new Exception("Can't add new roles to event with open registration.");
|
||||||
if (!EmoteHelper.TryParse(emote, out IEmote parsedEmote))
|
if (!EmoteHelper.TryParse(emote, out IEmote parsedEmote))
|
||||||
throw new ArgumentException("Invalid emote provided.");
|
throw new ArgumentException("Invalid emote provided.");
|
||||||
if(@event.Roles != null && @event.Roles.Count(r => r.Emote == parsedEmote.ToString()) > 0)
|
if(@event.Roles != null && @event.Roles.Count(r => r.Emote == parsedEmote.ToString()) > 0)
|
||||||
@@ -205,73 +260,95 @@ namespace EventBot.Modules
|
|||||||
Emote = parsedEmote.ToString(),
|
Emote = parsedEmote.ToString(),
|
||||||
Event = @event
|
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);
|
_database.Add(er);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Added event role `{er.Id}` for event `{er.Event.Id}`, title: `{er.Title}`, description: `{er.Description}`, maxPart: `{er.MaxParticipants}`, emote: {er.Emote}");
|
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")]
|
[Command("role update title")]
|
||||||
[Summary("Updates role's title")]
|
[Name("Update role's title")]
|
||||||
|
[Summary("Updates the role's title.")]
|
||||||
public async Task UpdateEventRoleTitle(
|
public async Task UpdateEventRoleTitle(
|
||||||
[Summary("Role witch to update.")] EventRole eventRole,
|
[Summary("Which role to update.")] EventRole eventRole,
|
||||||
[Summary("New title for role.")][Remainder] string title)
|
[Summary("The new title for the role.")][Remainder] string title)
|
||||||
{
|
{
|
||||||
if(eventRole == null)
|
if(eventRole == null)
|
||||||
throw new Exception("Please provide correct role.");
|
throw new Exception("Please provide the correct role info, this one does not exist.");
|
||||||
if (!eventRole.Event.Active)
|
if (!eventRole.Event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
eventRole.Title = title;
|
eventRole.Title = title;
|
||||||
var s = _database.SaveChangesAsync();
|
var s = _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Updated event role `{eventRole.Id}` title to `{eventRole.Title}`");
|
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 s;
|
||||||
await _events.UpdateEventMessage(eventRole.Event);
|
await _events.UpdateEventMessage(eventRole.Event);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("role update desc")]
|
[Priority(2)]
|
||||||
[Summary("Updates role's description.")]
|
[Command("role update description")]
|
||||||
|
[Alias("role update desc")]
|
||||||
|
[Name("Update role's description")]
|
||||||
|
[Summary("Updates the role's description.")]
|
||||||
public async Task UpdateEventRoleDescription(
|
public async Task UpdateEventRoleDescription(
|
||||||
[Summary("Role witch to update.")] EventRole eventRole,
|
[Summary("Which role to update.")] EventRole eventRole,
|
||||||
[Summary("New description for role.")][Remainder] string description)
|
[Summary("New description for the role.")][Remainder] string description)
|
||||||
{
|
{
|
||||||
if (eventRole == null)
|
if (eventRole == null)
|
||||||
throw new Exception("Please provide correct role.");
|
throw new Exception("Please provide the correct role ID, this one does not exist.");
|
||||||
if (!eventRole.Event.Active)
|
if (!eventRole.Event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
eventRole.Description = description;
|
eventRole.Description = description;
|
||||||
var s = _database.SaveChangesAsync();
|
var s = _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Updated event role `{eventRole.Id}` description to `{eventRole.Description}`");
|
await ReplyAsync($"Updated event role's `{eventRole.Id}` description to `{eventRole.Description}`");
|
||||||
await s;
|
await s;
|
||||||
await _events.UpdateEventMessage(eventRole.Event);
|
await _events.UpdateEventMessage(eventRole.Event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("role update slots")]
|
[Command("role update slots")]
|
||||||
[Summary("Updates role's maximum participants count.")]
|
[Name("Update role's slots")]
|
||||||
|
[Summary("Updates a role's maximum participants count.")]
|
||||||
public async Task UpdateEventRoleMaxParticipants(
|
public async Task UpdateEventRoleMaxParticipants(
|
||||||
[Summary("Role witch to update.")] EventRole eventRole,
|
[Summary("Which role to update.")] EventRole eventRole,
|
||||||
[Summary("New maximum participant count for role.")] int maxParticipants)
|
[Summary("New maximum participant count for role.")] int maxParticipants)
|
||||||
{
|
{
|
||||||
if (eventRole == null)
|
if (eventRole == null)
|
||||||
throw new Exception("Please provide correct role.");
|
throw new Exception("Please provide the correct role info, this one does not exist.");
|
||||||
if (!eventRole.Event.Active)
|
if (!eventRole.Event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
eventRole.MaxParticipants = maxParticipants;
|
eventRole.MaxParticipants = maxParticipants;
|
||||||
var s = _database.SaveChangesAsync();
|
var s = _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Updated event role `{eventRole.Id}` maximum participant count to `{eventRole.MaxParticipants}`");
|
await ReplyAsync($"Updated event role `{eventRole.Id}`'s maximum participant count to `{eventRole.MaxParticipants}`");
|
||||||
await s;
|
await s;
|
||||||
await _events.UpdateEventMessage(eventRole.Event);
|
await _events.UpdateEventMessage(eventRole.Event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("role update emote")]
|
[Command("role update emote")]
|
||||||
[Summary("Updates role's emote.")]
|
[Name("Update role's role")]
|
||||||
|
[Summary("Updates a role's emote.")]
|
||||||
public async Task UpdateEventRoleEmote(
|
public async Task UpdateEventRoleEmote(
|
||||||
[Summary("Role witch to update.")] EventRole eventRole,
|
[Summary("Which role to update.")] EventRole eventRole,
|
||||||
[Summary("New emote for the role.")] string emote)
|
[Summary("New emote for the role.")] string emote)
|
||||||
{
|
{
|
||||||
if (eventRole == null)
|
if (eventRole == null)
|
||||||
throw new Exception("Please provide correct role.");
|
throw new Exception("Please provide the correct role info, this one does not exist.");
|
||||||
if (eventRole.Event.MessageId != 0)
|
if (eventRole.Event.MessageId != 0)
|
||||||
throw new Exception("Role emote can't be edited while event is open for registrasion.");
|
throw new Exception("A role's emote cannot be edited while the event is open for registration.");
|
||||||
if (!eventRole.Event.Active)
|
if (!eventRole.Event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
if (!EmoteHelper.TryParse(emote, out IEmote parsedEmote))
|
if (!EmoteHelper.TryParse(emote, out IEmote parsedEmote))
|
||||||
@@ -286,19 +363,21 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command()]
|
[Command()]
|
||||||
|
[Alias("info")]
|
||||||
|
[Name("Event info")]
|
||||||
[Summary("Get info about event.")]
|
[Summary("Get info about event.")]
|
||||||
public async Task EventInfo(
|
public async Task EventInfo(
|
||||||
[Summary("Event about witch info is wanted.")] Event @event = null)
|
[Summary("Event ID of event you wish to know more of.")] Event @event = null)
|
||||||
{
|
{
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("No events were found for this guild.");
|
throw new Exception("No events were found for this discord server.");
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithTitle(@event.Title)
|
.WithTitle(@event.Title)
|
||||||
.WithDescription(@event.Description)
|
.WithDescription(@event.Description)
|
||||||
.WithTimestamp(@event.Opened)
|
.WithTimestamp(@event.Opened)
|
||||||
.WithFooter($"EventId: {@event.Id}; MessageId: {@event.MessageId}; MessageChannelId: {@event.MessageChannelId}")
|
.WithFooter($"EventId: {@event.Id}; MessageID: {@event.MessageId}; MessageChannelID: {@event.MessageChannelId}")
|
||||||
.AddField("Active", @event.Active ? "Yes" : "No", true)
|
.AddField("Active", @event.Active ? "Yes" : "No", true)
|
||||||
.AddField("Type", @event.Type, true)
|
.AddField("Type", @event.Type, true)
|
||||||
.AddField("Participants", @event.ParticipantCount, true);
|
.AddField("Participants", @event.ParticipantCount, true);
|
||||||
@@ -314,14 +393,43 @@ namespace EventBot.Modules
|
|||||||
|
|
||||||
await ReplyAsync(embed: embed.Build());
|
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)]
|
[Priority(1)]
|
||||||
[Command("role")]
|
[Command("role")]
|
||||||
[Summary("Gets role info.")]
|
[Alias("role info")]
|
||||||
|
[Name("Role info")]
|
||||||
|
[Summary("Gets info about a role.")]
|
||||||
public async Task EventRoleInfo(
|
public async Task EventRoleInfo(
|
||||||
[Summary("Role about witch info is wanted.")] EventRole eventRole)
|
[Summary("Role you wish to have more info about.")] EventRole eventRole)
|
||||||
{
|
{
|
||||||
if (eventRole == null)
|
if (eventRole == null)
|
||||||
throw new Exception("Please provide correct role.");
|
throw new Exception("Please provide the correct role info, this one does not exist.");
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithTitle($"{eventRole.Emote} {eventRole.Title}")
|
.WithTitle($"{eventRole.Emote} {eventRole.Title}")
|
||||||
.WithDescription($"{eventRole.Description}")
|
.WithDescription($"{eventRole.Description}")
|
||||||
@@ -338,7 +446,10 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(1)]
|
||||||
[Command("open")]
|
[Command("open")]
|
||||||
|
[Alias("start", "begin")]
|
||||||
|
[Name("Open event")]
|
||||||
[Summary("Open registration for event here.")]
|
[Summary("Open registration for event here.")]
|
||||||
public async Task EventOpen(
|
public async Task EventOpen(
|
||||||
[Summary("Event to open")] Event @event = null)
|
[Summary("Event to open")] Event @event = null)
|
||||||
@@ -346,7 +457,7 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("No events were found for this guild.");
|
throw new Exception("No events were found for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
|
|
||||||
@@ -370,7 +481,11 @@ namespace EventBot.Modules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Priority(1)]
|
||||||
[Command("close")]
|
[Command("close")]
|
||||||
|
[Alias("stop", "end")]
|
||||||
|
[Name("Close event")]
|
||||||
[Summary("Closes event registration.")]
|
[Summary("Closes event registration.")]
|
||||||
public async Task EventClose(
|
public async Task EventClose(
|
||||||
[Summary("Event to close")] Event @event = null)
|
[Summary("Event to close")] Event @event = null)
|
||||||
@@ -378,7 +493,7 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("No events were found for this guild.");
|
throw new Exception("No events were found for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
if (@event.MessageId == 0)
|
if (@event.MessageId == 0)
|
||||||
@@ -387,10 +502,14 @@ namespace EventBot.Modules
|
|||||||
@event.MessageId = 0;
|
@event.MessageId = 0;
|
||||||
@event.MessageChannelId = 0;
|
@event.MessageChannelId = 0;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync($"Event `{@event.Id}` registration has been closed, it's registration message will now be normal message.");
|
await ReplyAsync($"Event's `{@event.Id}` registration has been closed, its registration message will now be normal message.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Priority(1)]
|
||||||
[Command("finalize")]
|
[Command("finalize")]
|
||||||
|
[Alias("archive")]
|
||||||
|
[Name("Archive event")]
|
||||||
[Summary("Archives event and reverts all role additions. This is irreversable.")]
|
[Summary("Archives event and reverts all role additions. This is irreversable.")]
|
||||||
public async Task EventFinilize(
|
public async Task EventFinilize(
|
||||||
[Summary("Event to finilize")] Event @event = null)
|
[Summary("Event to finilize")] Event @event = null)
|
||||||
@@ -398,30 +517,41 @@ namespace EventBot.Modules
|
|||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("No events were found for this guild.");
|
throw new Exception("No events were found for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is already finalized.");
|
throw new Exception("This event is already finalized.");
|
||||||
|
|
||||||
@event.Active = false;
|
@event.Active = false;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
|
||||||
await ReplyAsync($"Event `{@event.Id}` has been finilized. Removing participant roles...");
|
await ReplyAsync($"Event `{@event.Id}` has been finalized. Removing participant roles..");
|
||||||
if (@event.Guild.ParticipantRoleId != 0)
|
if (@event.Guild.ParticipantRoleId != 0)
|
||||||
foreach (var participant in @event.Participants)
|
foreach (var participant in @event.Participants)
|
||||||
{
|
{
|
||||||
var user = Context.Guild.GetUser(participant.UserId);
|
var user = Context.Guild.GetUser(participant.UserId);
|
||||||
await user.RemoveRoleAsync(Context.Guild.GetRole(@event.Guild.ParticipantRoleId));
|
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!");
|
await ReplyAsync($"Everyone's roles have been removed. I hope it was fun!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(1)]
|
||||||
[Command("list")]
|
[Command("list")]
|
||||||
|
[Alias("all")]
|
||||||
|
[Name("Lists events")]
|
||||||
[Summary("Lists all prevous events that took on this server.")]
|
[Summary("Lists all prevous events that took on this server.")]
|
||||||
public async Task EventArchive()
|
public async Task EventArchive()
|
||||||
{
|
{
|
||||||
var guildEvents = _database.Events.Where(e => e.GuildId == Context.Guild.Id).OrderBy(e => e.Opened).ToList();
|
var guildEvents = _database.Events.Where(e => e.GuildId == Context.Guild.Id).OrderBy(e => e.Opened).ToList();
|
||||||
if (guildEvents.Count() == 0)
|
if (guildEvents.Count() == 0)
|
||||||
throw new Exception("There are no events that roon on this server.");
|
throw new Exception("There are no events that have been run on this server.");
|
||||||
|
|
||||||
var pagedEvents = guildEvents
|
var pagedEvents = guildEvents
|
||||||
.Select((e, i) => new { Event = e, Index = i })
|
.Select((e, i) => new { Event = e, Index = i })
|
||||||
@@ -429,7 +559,7 @@ namespace EventBot.Modules
|
|||||||
.Select(g => g.Select(o => o.Event));
|
.Select(g => g.Select(o => o.Event));
|
||||||
var pager = new PaginatedMessage()
|
var pager = new PaginatedMessage()
|
||||||
{
|
{
|
||||||
Title = "List al all prevous events.",
|
Title = "Lists all previous events.",
|
||||||
Color = Color.Blue,
|
Color = Color.Blue,
|
||||||
Options = new PaginatedAppearanceOptions()
|
Options = new PaginatedAppearanceOptions()
|
||||||
{
|
{
|
||||||
@@ -447,27 +577,33 @@ namespace EventBot.Modules
|
|||||||
await PagedReplyAsync(pager);
|
await PagedReplyAsync(pager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("participant add")]
|
[Command("participant add")]
|
||||||
[Summary("Add user to event role. Acts like join command.")]
|
[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")]
|
||||||
public async Task EventParticipantAdd(
|
public async Task EventParticipantAdd(
|
||||||
[Summary("User id or mention")] IUser user,
|
[Summary("User ID or discord mention.")] IUser user,
|
||||||
[Summary("Role emote or role id to join.")] string emoteOrId,
|
[Summary("Role emote or role ID to join.")] string emoteOrId,
|
||||||
[Summary("Extra information that migth be needed by organizers.")] string extraInformation = null,
|
[Summary("Extra information that might be needed by organizers.")] string extraInformation = null,
|
||||||
[Summary("Optional event ID for joining event that is not most recent one.")] Event @event = null)
|
[Summary("Optional event ID for joining event that is not the most recent one.")] Event @event = null)
|
||||||
{
|
{
|
||||||
EventRole er;
|
EventRole er;
|
||||||
if (!(user is SocketGuildUser guildUser))
|
if (!(user is SocketGuildUser guildUser))
|
||||||
throw new Exception("This command must be executed inside guild.");
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null & !(int.TryParse(emoteOrId, out int roleId)))
|
if (@event == null & !(int.TryParse(emoteOrId, out int roleId)))
|
||||||
throw new Exception("Unable to locate any events for this guild.");
|
throw new Exception("Unable to locate any events for this discord server.");
|
||||||
else if (@event == null || roleId != 0)
|
else if (@event == null || roleId != 0)
|
||||||
er = _database.EventRoles.FirstOrDefault(r => r.Id == roleId);
|
er = _database.EventRoles.FirstOrDefault(r => r.Id == roleId);
|
||||||
else
|
else
|
||||||
er = @event.Roles.FirstOrDefault(r => r.Emote == emoteOrId);
|
er = @event.Roles.FirstOrDefault(r => r.Emote == emoteOrId);
|
||||||
if (er == null)
|
if (er == null)
|
||||||
throw new ArgumentException("Invalid emote or event id specified");
|
throw new ArgumentException("Invalid emote or event ID specified");
|
||||||
if (!er.Event.Active)
|
if (!er.Event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
|
|
||||||
@@ -475,37 +611,30 @@ namespace EventBot.Modules
|
|||||||
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
await Context.Message.DeleteAsync(); // Protect somewhat sensitive data.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Priority(2)]
|
||||||
[Command("participant remove")]
|
[Command("participant remove")]
|
||||||
|
[Alias("participant delete")]
|
||||||
|
[Name("Remove participant")]
|
||||||
[Summary("Remove participant from event role.")]
|
[Summary("Remove participant from event role.")]
|
||||||
public async Task EventParticipantRemove(
|
public async Task EventParticipantRemove(
|
||||||
[Summary("User that is participanting id or mention")] IUser user,
|
[Summary("User that is participating's ID or discord mention.")] IUser user,
|
||||||
[Summary("Event to romove participant from")] Event @event = null)
|
[Summary("Event to remove the participant from.")] Event @event = null)
|
||||||
{
|
{
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
@event = _events.FindEventBy(Context.Guild);
|
@event = _events.FindEventBy(Context.Guild);
|
||||||
if (@event == null)
|
if (@event == null)
|
||||||
throw new Exception("No events were found for this guild.");
|
throw new Exception("No events were found for this discord server.");
|
||||||
if (!@event.Active)
|
if (!@event.Active)
|
||||||
throw new Exception("This event is finalized. Please make a new event.");
|
throw new Exception("This event is finalized. Please make a new event.");
|
||||||
|
if (!(user is IGuildUser guildUser) || !(Context.User is IGuildUser initiator))
|
||||||
|
throw new Exception("This command must be executed inside a discord server.");
|
||||||
|
|
||||||
if (!(user is IGuildUser guildUser))
|
|
||||||
throw new Exception("This command must be executed inside guild.");
|
|
||||||
|
|
||||||
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($"They were in `{participant.Role.Title}` role")
|
|
||||||
.WithColor(Color.Red);
|
|
||||||
if (participant.UserData != null)
|
|
||||||
embed.AddField("Provided details", $"`{participant.UserData}`");
|
|
||||||
|
|
||||||
|
await _events.RemoveParticipant(guildUser, @event, initiator);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
await ReplyAsync($"{guildUser} has been removed from event.");
|
||||||
await _events.UpdateEventMessage(@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,10 +49,7 @@ namespace EventBot
|
|||||||
private ServiceProvider ConfigureServices()
|
private ServiceProvider ConfigureServices()
|
||||||
{
|
{
|
||||||
return new ServiceCollection()
|
return new ServiceCollection()
|
||||||
.AddSingleton(s => new DiscordSocketClient(new DiscordSocketConfig() {
|
.AddSingleton(s => new DiscordSocketClient(getDiscordSocketConfig()))
|
||||||
LogLevel = LogSeverity.Debug,
|
|
||||||
MessageCacheSize = 1500
|
|
||||||
}))
|
|
||||||
.AddSingleton<CommandService>()
|
.AddSingleton<CommandService>()
|
||||||
.AddSingleton<CommandHandlingService>()
|
.AddSingleton<CommandHandlingService>()
|
||||||
.AddSingleton<EventManagementService>()
|
.AddSingleton<EventManagementService>()
|
||||||
@@ -67,5 +64,19 @@ namespace EventBot
|
|||||||
//.AddSingleton<PictureService>()
|
//.AddSingleton<PictureService>()
|
||||||
.BuildServiceProvider();
|
.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": {
|
"EventBot": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"dbconnection": "Server=localhost;Database=eventbot;User=root;Password=tux;",
|
"dbconnection": "Server=server;Database=eventbot;User=eventbot;Password=password;",
|
||||||
"token": "<insert Token here>"
|
"token": "token here"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Docker": {
|
"Docker": {
|
||||||
|
@@ -35,6 +35,7 @@ namespace EventBot.Services
|
|||||||
|
|
||||||
_discord = services.GetRequiredService<DiscordSocketClient>();
|
_discord = services.GetRequiredService<DiscordSocketClient>();
|
||||||
_discord.GuildAvailable += OnGuildAvaivable;
|
_discord.GuildAvailable += OnGuildAvaivable;
|
||||||
|
_discord.JoinedGuild += OnGuildAvaivable;
|
||||||
}
|
}
|
||||||
public DatabaseService(): base() {}
|
public DatabaseService(): base() {}
|
||||||
|
|
||||||
|
@@ -25,21 +25,45 @@ namespace EventBot.Services
|
|||||||
|
|
||||||
_discord.ReactionAdded += ReactionAddedAsync;
|
_discord.ReactionAdded += ReactionAddedAsync;
|
||||||
_discord.MessageDeleted += MessageDeletedAsync;
|
_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)
|
public async Task TryJoinEvent(IGuildUser user, EventRole er, string extra, bool extraChecks = true)
|
||||||
{
|
{
|
||||||
if (er.Event.GuildId != user.GuildId)
|
if (er.Event.GuildId != user.GuildId)
|
||||||
throw new Exception("Cross guild events are fobidden.");
|
throw new Exception("Cross server events are forbidden.");
|
||||||
if (extraChecks && er.ReamainingOpenings <= 0)
|
if (extraChecks && er.ReamainingOpenings <= 0)
|
||||||
throw new Exception("No openings left.");
|
throw new Exception("No openings are left.");
|
||||||
if(er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
if(er.Event.ParticipantCount > 0 && er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
||||||
throw new Exception("You are already participating.");
|
throw new Exception("You are already participating.");
|
||||||
if(extraChecks && !er.Event.Active)
|
if(extraChecks && !er.Event.Active)
|
||||||
throw new Exception("Event is closed.");
|
throw new Exception("Event is closed.");
|
||||||
|
|
||||||
if (er.Event.Guild.ParticipantRoleId != 0)
|
if (er.Event.Guild.ParticipantRoleId != 0)
|
||||||
await user.AddRoleAsync(user.Guild.GetRole(er.Event.Guild.ParticipantRoleId));
|
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()
|
var ep = new EventParticipant()
|
||||||
{
|
{
|
||||||
@@ -63,6 +87,42 @@ namespace EventBot.Services
|
|||||||
await (await user.Guild.GetTextChannelAsync(er.Event.Guild.EventRoleConfirmationChannelId)).SendMessageAsync(embed: embed.Build());
|
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)
|
public Event FindEventBy(IGuild guild, bool bypassActive = false)
|
||||||
{
|
{
|
||||||
return _database.Events.OrderByDescending(e => e.Opened).FirstOrDefault(e => e.GuildId == guild.Id && (e.Active || bypassActive));
|
return _database.Events.OrderByDescending(e => e.Opened).FirstOrDefault(e => e.GuildId == guild.Id && (e.Active || bypassActive));
|
||||||
@@ -95,12 +155,12 @@ namespace EventBot.Services
|
|||||||
if (@event.Type == Event.EventParticipactionType.Quick)
|
if (@event.Type == Event.EventParticipactionType.Quick)
|
||||||
embed.Description += "\r\nTo participate in this event react with following emotes:";
|
embed.Description += "\r\nTo participate in this event react with following emotes:";
|
||||||
if (@event.Type == Event.EventParticipactionType.Detailed)
|
if (@event.Type == Event.EventParticipactionType.Detailed)
|
||||||
embed.Description += "\r\nTo participate in this event use command `join <emote or id> <extra information>` as following emotes are awaivable:";
|
embed.Description += "\r\nTo participate in this event use command `join <emote or id> <extra information>` as following emotes are available:";
|
||||||
|
|
||||||
embed.WithFields(@event.Roles
|
embed.WithFields(@event.Roles
|
||||||
.OrderBy(e => e.SortNumber)
|
.OrderBy(e => e.SortNumber)
|
||||||
.Select(e => new EmbedFieldBuilder()
|
.Select(e => new EmbedFieldBuilder()
|
||||||
.WithName($"{e.Emote} `{e.Id}`: *{e.Title}*`{ (e.MaxParticipants > 0 ? $" - {e.ReamainingOpenings} ramaining" : "")} - {e.ParticipantCount} participating.`")
|
.WithName($"{e.Emote} `{e.Id}`: *{e.Title}*`{ (e.MaxParticipants > 0 ? $" - {e.ReamainingOpenings} remaining" : "")} - {e.ParticipantCount} participating.`")
|
||||||
.WithValue($"{e.Description}")
|
.WithValue($"{e.Description}")
|
||||||
));
|
));
|
||||||
return embed;
|
return embed;
|
||||||
@@ -141,7 +201,7 @@ namespace EventBot.Services
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (reaction.User.IsSpecified)
|
if (reaction.User.IsSpecified)
|
||||||
await reaction.User.Value.SendMessageAsync($"Error ocured while processing your reaction: \r\n{ex.GetType()}: {ex.Message}");
|
await reaction.User.Value.SendMessageAsync($"Error occured while processing your reaction: \r\n{ex.GetType()}: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
README
6
README
@@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
`set dbconnection="Server=localhost;Database=eventbot;User=root;Password=password;"`
|
|
||||||
|
|
||||||
|
|
||||||
`Add-Migration InitialDatabase -Context MySqlDatabaseService -OutputDir Migrations\MySql`
|
|
||||||
`Add-Migration InitialDatabase -Context SqliteDatabaseService -OutputDir Migrations\Sqlite`
|
|
14
README.md
Normal file
14
README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# EventBot
|
||||||
|
|
||||||
|
## Environment variables
|
||||||
|
### `token` variable
|
||||||
|
This is variable for discord bot's token obtained from discord developer panel.
|
||||||
|
### `dbconnection` variable
|
||||||
|
This is environment variable for Mysql / MariaDb database connection. Example connection string:
|
||||||
|
|
||||||
|
```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