Skip to content

Commit

Permalink
Merge pull request #381 from fit-ctu-discord/v2022.4
Browse files Browse the repository at this point in the history
V2022.4
  • Loading branch information
ostorc authored Sep 18, 2022
2 parents 3ff0953 + 89e1906 commit 6a22243
Show file tree
Hide file tree
Showing 70 changed files with 2,146 additions and 2,005 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2022.3.1</Version>
<Version>2022.4</Version>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
Expand Down
9 changes: 5 additions & 4 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<ItemGroup>
<PackageReference Update="Chronic.Core" Version="0.4.0" />
<PackageReference Update="Cronos" Version="0.7.1" />
<PackageReference Update="DSharpPlus" Version="4.2.0" />
<PackageReference Update="DSharpPlus.CommandsNext" Version="4.2.0" />
<PackageReference Update="DSharpPlus.Interactivity" Version="4.2.0" />
<PackageReference Update="DSharpPlus" Version="4.3.0-nightly-01169" />
<PackageReference Update="DSharpPlus.Interactivity" Version="4.3.0-nightly-01169" />
<PackageReference Update="DSharpPlus.SlashCommands" Version="4.3.0-nightly-01169" />
<PackageReference Update="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Update="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="6.0.8" />
Expand All @@ -15,13 +15,14 @@
<PackageReference Update="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Update="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Update="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.6" />
<PackageReference Update="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Update="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Update="coverlet.collector" Version="3.1.2" />
<PackageReference Update="xunit" Version="2.4.2" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Update="Shouldly" Version="4.1.0" />
<PackageReference Update="Html2Markdown" Version="4.0.0.427" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
postgres-botner:
container_name: postgres-botner
image: postgres:12
image: postgres
environment:
POSTGRES_USER: honza-bot
POSTGRES_PASSWORD: postgres
Expand Down
58 changes: 34 additions & 24 deletions docs/howto.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# How to Start

## Configuration
## Prerequisites
Make sure you have the latest .NET Core and ASP.NET installed. You can find
install instructions [here][dotnet].
You'll also need to have docker installed.

## About our configuration
For configuration, we use a combination of the standard `appsettings.json` file and `secrets.json`.
Non-sensitive information is stored in the `appsettings.json` file
and sensitive information is stored in place outside of the git repository.
Expand Down Expand Up @@ -45,29 +49,17 @@ Discord token can be found on [Discord developer portal][discordDev].
Database URL in the example is working with provided docker image
which can be found in [compose file][compose].

## Setup
## Initial configuration
To be able to run the bot locally you need to setup some configs.
- Set the Discord token of your test app and the `DATABASE_URL` parameter
in [`secrets.json`][secrets] the other secrets are not needed for your average
development needs.
- Change `Discord.GuildId` in `appsettings.Development.json` to the id of your
test guild.
- Change `CustomVoiceOptions.ClickChannelId` in `appsettings.Development.json` to
an id of a voice channel in your test guild.

Before you can start working on the botyou need to download the latest released version of .NET.
Available version can be found [here][dotnet].
We also need to have access to PostgresDB.
For development we use docker image,
so you will need to download it too,
or you can use other Postgres instance.

## Startup

Before starting the bot itself we will need to start DB by the following command:

```sh
docker-compose up -d
```

if everything went well you will see `Starting postgres-botner ... done`.

After that, you can start up the project in your favorite IDE
or by typing `dotnet run --project ./src/HonzaBotner/`.

## Migrations
## Database and migrations

To modify the database scheme we need to process migrations.
For that, we need to install a tool that does that.
Expand All @@ -81,7 +73,7 @@ We can see generated files in `src/HonzaBotner/Migrations`.
If everything is OK we can update our DB by the following command:

```sh
dotnet ef database update
dotnet ef database update --project ./src/HonzaBotner
```

With this, we will get migration based on our code
Expand All @@ -95,6 +87,24 @@ cd src/HonzaBotner
dotnet ef migrations add "Name of migration"
```

# Startup

Before starting the bot itself we will need to start DB.

If you are on Linux start the docker service using `systemctl start docker`

Than start the DB using the following command:

```sh
docker-compose up -d
```

if everything went well you will see `Starting postgres-botner ... done`.

After that, you can start up the project in your favorite IDE
or by typing `dotnet run --project ./src/HonzaBotner/`.


[dotnet]: https://dotnet.microsoft.com/download
[compose]: ../docker-compose.yml
[discordDev]: https://discord.com/developers/applications
Expand Down
2 changes: 2 additions & 0 deletions src/HonzaBotner.Database/HonzaBotnerDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ protected override void OnModelCreating(ModelBuilder builder)
new RoleBindingMapper().Map(builder.Entity<RoleBinding>());
new WarningMapper().Map(builder.Entity<Warning>());
new ReminderMapper().Map(builder.Entity<Reminder>());
new NewsConfigMapper().Map(builder.Entity<NewsConfig>());
}

public DbSet<Verification> Verifications { get; set; }
public DbSet<CountedEmoji> CountedEmojis { get; set; }
public DbSet<RoleBinding> RoleBindings { get; set; }
public DbSet<Warning> Warnings { get; set; }
public DbSet<Reminder> Reminders { get; set; }
public DbSet<NewsConfig> NewsConfigs { get; set; }
}
20 changes: 20 additions & 0 deletions src/HonzaBotner.Database/Mappers/NewsConfigMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace HonzaBotner.Database.Mappers;

internal sealed class NewsConfigMapper : IEntityMapper<NewsConfig>
{
public void Map(EntityTypeBuilder<NewsConfig> builder)
{
builder.HasKey(c => c.Id);
builder.HasIndex(c => c.Name).IsUnique();

builder.Ignore(c => c.Channels);

builder.Property(c => c.Name).IsRequired();
builder.Property(c => c.Source).IsRequired();
builder.Property(c => c.ChannelsData).IsRequired();
builder.Property(c => c.NewsProviderType).IsRequired();
builder.Property(c => c.PublisherType).IsRequired();
}
}
29 changes: 29 additions & 0 deletions src/HonzaBotner.Database/NewsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Linq;

namespace HonzaBotner.Database;

public class NewsConfig
{
public int Id { get; set; }

public string Name { get; set; }
public string Source { get; set; }
public DateTime LastFetched { get; set; }
public string ChannelsData { get; set; }

public ulong[] Channels
{
get
{
if (ChannelsData == string.Empty) return Array.Empty<ulong>();
return ChannelsData.Split(";").Select(ulong.Parse).ToArray();
}
set => ChannelsData = string.Join(';', value);
}

public string NewsProviderType { get; set; }
public string PublisherType { get; set; }

public bool Active { get; set; }
}
18 changes: 0 additions & 18 deletions src/HonzaBotner.Discord.Services/Attributes/CustomBaseAttribute.cs

This file was deleted.

This file was deleted.

37 changes: 0 additions & 37 deletions src/HonzaBotner.Discord.Services/Attributes/RequireModAttribute.cs

This file was deleted.

Loading

0 comments on commit 6a22243

Please sign in to comment.