Compare commits

..

21 Commits

Author SHA1 Message Date
Karolis2011
060d9e3785 Adds a check 2019-09-05 21:50:59 +03:00
Karolis2011
203811366b Updates things and adds debug options 2019-09-05 21:23:41 +03:00
Karolis2011
e9f59780ed Adds role specific channels.
Read ME update

Updating tile of role will update revelant channels and roles.

Added command examples.

Fixese leaks
2019-08-01 20:25:28 +03:00
Karolis2011
18657d7fab Help part 2 2019-08-01 20:25:28 +03:00
Karolis2011
b5702faa31 Better help part 1 2019-08-01 20:25:28 +03:00
Geeves
9ac6343406 Update EventBot/Modules/EventModule.cs 2019-08-01 20:25:28 +03:00
Geeves
c28ffe2ade Update EventBot/Modules/EventModule.cs 2019-08-01 20:25:28 +03:00
Geeves
92459fb4de Update EventBot/Modules/EventModule.cs 2019-08-01 20:25:28 +03:00
Geeves
32246855fa Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:28 +03:00
Geeves
941716b19d Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:28 +03:00
Geeves
9ede67c61b Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:28 +03:00
Geeves
021c497288 Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:27 +03:00
Geeves
5d32d3b611 Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:27 +03:00
Geeves
17e08c6f01 Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:27 +03:00
Geeves
6ce26b1d39 Update EventBot/Modules/EventModule.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:27 +03:00
Geeves
05143db059 Update EventBot/Misc/EventRoleTypeReader.cs
Co-Authored-By: Karolis <Karolis2011@users.noreply.github.com>
2019-08-01 20:25:27 +03:00
Geeves
0522482685 final commit 2019-08-01 20:25:27 +03:00
Karolis2011
e1f376f92c Travis you can do it. 2019-08-01 20:25:27 +03:00
Karolis2011
f73d84803e Addes travis and README 2019-08-01 20:25:27 +03:00
Geeves
2a80032cae spellfixes for commands 2019-08-01 20:25:27 +03:00
Geeves
cea06e205c spellfixes 2019-08-01 20:25:27 +03:00
19 changed files with 790 additions and 55 deletions

View 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;
}
}
}

View File

@@ -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

View File

@@ -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; }
} }

View File

@@ -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>

View 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
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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");

View 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
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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");

View 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;
}
}
}

View File

@@ -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`");
} }
} }
} }

View File

@@ -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,8 +26,13 @@ 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:")]
[Example("join 5 \"John Smith\"")]
[Example("join :gun: \"Tpr. James\" 2")]
public async Task JoinEvent(
[Summary("Role emote or role ID to join the most recent event.")] string emoteOrId, [Summary("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("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) [Summary("Optional event ID, used to join an event that started before the most recent one.")] Event @event = null)
@@ -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,9 +72,11 @@ 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);
@@ -78,9 +89,11 @@ namespace EventBot.Modules
await s; await s;
} }
[Priority(2)]
[Command("config partrole")] [Command("config partrole")]
[Name("Configure participant role")]
[Summary("Sets discord role to assign when the user selects a role.")] [Summary("Sets discord role to assign when the user selects a role.")]
public async Task SetParticipationRole( 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);
@@ -93,9 +106,36 @@ 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")]
[Alias("add", "create")]
[Name("Create event")]
[Summary("Creates a new event.")] [Summary("Creates a new event.")]
public async Task NewEvent( [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)
@@ -116,7 +156,9 @@ namespace EventBot.Modules
await ReplyAsync($"Created new {@event.Type} event `{title}`, with description: `{description}`. Its 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")]
[Name("Update event's title")]
[Summary("Updates the 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,
@@ -133,7 +175,10 @@ namespace EventBot.Modules
await ReplyAsync($"Updated event's (`{@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")]
[Alias("update desc")]
[Name("Update event's description")]
[Summary("Updates the 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,
@@ -151,8 +196,12 @@ namespace EventBot.Modules
await _events.UpdateEventMessage(@event); await _events.UpdateEventMessage(@event);
} }
[Priority(2)]
[Command("update type")] [Command("update type")]
[Name("Update event's type")]
[Summary("Updates the event 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)
@@ -174,8 +223,14 @@ namespace EventBot.Modules
} }
[Priority(2)]
[Command("role new")] [Command("role new")]
[Alias("role add", "role create")]
[Name("Add role")]
[Summary("Adds a new role to the event.")] [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 of the role.")] string title, [Summary("Title of the role.")] string title,
[Summary("Description of the role.")] string description, [Summary("Description of the role.")] string description,
@@ -205,13 +260,24 @@ 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}`, slots: `{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 the role's title")] [Name("Update role's title")]
[Summary("Updates the role's title.")]
public async Task UpdateEventRoleTitle( public async Task UpdateEventRoleTitle(
[Summary("Which role to update.")] EventRole eventRole, [Summary("Which role to update.")] EventRole eventRole,
[Summary("The new title for the role.")][Remainder] string title) [Summary("The new title for the role.")][Remainder] string title)
@@ -222,19 +288,26 @@ namespace EventBot.Modules
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();
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 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)]
[Command("role update description")]
[Alias("role update desc")]
[Name("Update role's description")]
[Summary("Updates the role's description.")] [Summary("Updates the role's description.")]
public async Task UpdateEventRoleDescription( public async Task UpdateEventRoleDescription(
[Summary("Which role to update.")] EventRole eventRole, [Summary("Which role to update.")] EventRole eventRole,
[Summary("New description for the role.")][Remainder] string description) [Summary("New description for the role.")][Remainder] string description)
{ {
if (eventRole == null) if (eventRole == null)
throw new Exception("Please provide the correct role info, this one does not exist."); 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;
@@ -244,7 +317,9 @@ namespace EventBot.Modules
await _events.UpdateEventMessage(eventRole.Event); await _events.UpdateEventMessage(eventRole.Event);
} }
[Priority(2)]
[Command("role update slots")] [Command("role update slots")]
[Name("Update role's slots")]
[Summary("Updates a role's maximum participants count.")] [Summary("Updates a role's maximum participants count.")]
public async Task UpdateEventRoleMaxParticipants( public async Task UpdateEventRoleMaxParticipants(
[Summary("Which role to update.")] EventRole eventRole, [Summary("Which role to update.")] EventRole eventRole,
@@ -262,7 +337,9 @@ namespace EventBot.Modules
} }
[Priority(2)]
[Command("role update emote")] [Command("role update emote")]
[Name("Update role's role")]
[Summary("Updates a role's emote.")] [Summary("Updates a role's emote.")]
public async Task UpdateEventRoleEmote( public async Task UpdateEventRoleEmote(
[Summary("Which role to update.")] EventRole eventRole, [Summary("Which role to update.")] EventRole eventRole,
@@ -286,6 +363,8 @@ 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 ID of event you wish to know more of.")] Event @event = null) [Summary("Event ID of event you wish to know more of.")] Event @event = null)
@@ -314,8 +393,37 @@ 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")]
[Alias("role info")]
[Name("Role info")]
[Summary("Gets info about a role.")] [Summary("Gets info about a role.")]
public async Task EventRoleInfo( public async Task EventRoleInfo(
[Summary("Role you wish to have more info about.")] EventRole eventRole) [Summary("Role you wish to have more info about.")] EventRole eventRole)
@@ -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)
@@ -369,8 +480,12 @@ namespace EventBot.Modules
throw new Exception("Event type in not implemented."); throw new Exception("Event type in not implemented.");
} }
} }
[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)
@@ -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}`'s registration has been closed, its 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)
@@ -405,23 +524,34 @@ namespace EventBot.Modules
@event.Active = false; @event.Active = false;
await _database.SaveChangesAsync(); await _database.SaveChangesAsync();
await ReplyAsync($"Event `{@event.Id}`'s has been finalized. 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("No events have been run 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 })
@@ -447,8 +577,14 @@ 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 discord 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,
@@ -475,10 +611,13 @@ 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's ID or discord mention.")] IUser user, [Summary("User that is participating's ID or discord mention.")] IUser user,
[Summary("Event to remove the participant from.")] Event @event = null) [Summary("Event to remove the participant from.")] Event @event = null)
{ {
if (@event == null) if (@event == null)
@@ -487,25 +626,15 @@ namespace EventBot.Modules
throw new Exception("No events were found for this discord server."); 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))
if (!(user is IGuildUser guildUser))
throw new Exception("This command must be executed inside a discord server."); 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 _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));
} }
} }
} }

View File

@@ -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;
}
} }
} }

View File

@@ -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": {

View File

@@ -58,7 +58,7 @@ namespace EventBot.Services
var context = new SocketCommandContext(_discord, message); var context = new SocketCommandContext(_discord, message);
GuildConfig guildConfig = context.Guild != null ? _database.GuildConfigs.FirstOrDefault(g => g.GuildId == context.Guild.Id) : null; GuildConfig guildConfig = context.Guild != null ? _database.GuildConfigs.FirstOrDefault(g => g.GuildId == context.Guild.Id) : null;
if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos))
if (guildConfig != null) if (guildConfig != null && string.IsNullOrEmpty(guildConfig.Prefix))
{ {
if (!message.HasStringPrefix(guildConfig.Prefix, ref argPos)) if (!message.HasStringPrefix(guildConfig.Prefix, ref argPos))
return; return;

View File

@@ -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() {}

View File

@@ -25,6 +25,28 @@ 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)
@@ -33,14 +55,16 @@ namespace EventBot.Services
throw new Exception("Cross server events are forbidden."); throw new Exception("Cross server events are forbidden.");
if (extraChecks && er.ReamainingOpenings <= 0) if (extraChecks && er.ReamainingOpenings <= 0)
throw new Exception("No openings are 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()
{ {
UserId = user.Id, UserId = user.Id,
@@ -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));

View File

@@ -8,6 +8,7 @@ This is environment variable for Mysql / MariaDb database connection. Example co
```Server=localhost,123;Database=eventbot;User=root;Password=password;``` ```Server=localhost,123;Database=eventbot;User=root;Password=password;```
## Making migrations
`Add-Migration InitialDatabase -Context MySqlDatabaseService -OutputDir Migrations\MySql` `Add-Migration InitialDatabase -Context MySqlDatabaseService -OutputDir Migrations\MySql`
`Add-Migration InitialDatabase -Context SqliteDatabaseService -OutputDir Migrations\Sqlite` `Add-Migration InitialDatabase -Context SqliteDatabaseService -OutputDir Migrations\Sqlite`