Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Blart #11

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Publish

on:
push:
branches:
- master

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET 7
uses: actions/[email protected]
with:
dotnet-version: '7.0.402'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build local Docker image
run: dotnet publish --arch x64 --os linux .
- name: Push to Docker Hub
run: docker push xroier/blart --all-tags
45 changes: 37 additions & 8 deletions BLART/BLART.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>2.3.0</AssemblyVersion>
<FileVersion>2.3.0</FileVersion>
<AssemblyVersion>2.4.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<PublishProfile>DefaultContainer</PublishProfile>
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:7.0</ContainerBaseImage>
<ContainerImageTags>$(FileVersion);latest</ContainerImageTags>
<ContainerRepository>xroier/blart</ContainerRepository>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.10.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.0-preview.2.22153.1" />
<PackageReference Include="MySqlConnector" Version="2.1.9" />
<ContainerEnvironmentVariable Include="DB_SERVER" Value="" Required="true" />
<ContainerEnvironmentVariable Include="DB_DATABASE" Value="" Required="true" />
<ContainerEnvironmentVariable Include="DB_USER" Value="" Required="true" />
<ContainerEnvironmentVariable Include="DB_PASSWORD" Value="" Required="true" />
<ContainerEnvironmentVariable Include="BOT_TOKEN" Value="" Required="true" />
<ContainerEnvironmentVariable Include="BOT_PREFIX" Value="~" Required="true" />
<ContainerEnvironmentVariable Include="DISC_STAFF_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="SPAM_LIMIT" Value="10" Required="true" />
<ContainerEnvironmentVariable Include="SPAM_TIMEOUT" Value="5" Required="true" />
<ContainerEnvironmentVariable Include="CHANNEL_RENT_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="CHANNEL_RENT_CATEGORY_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="LOGS_CHANNEL_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="DEBUG" Value="false" Required="true" />
<ContainerEnvironmentVariable Include="RED_ROLE_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="BUG_REPORT_CHANNEL_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="LENGHT_LIMIT" Value="200" Required="true" />
<ContainerEnvironmentVariable Include="CONTRIBUTOR_ROLE_ID" Value="668651927298375690" Required="true" />
<ContainerEnvironmentVariable Include="NW_API_KEY" Value="" Required="true" />
<ContainerEnvironmentVariable Include="STAFF_CHANNEL_ID" Value="0" Required="true" />
<ContainerEnvironmentVariable Include="CREDIT_ROLE_IDS" Value="0,1" Required="true" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.12.0" />
<PackageReference Include="linq2db" Version="5.3.2" />
<PackageReference Include="MySql.Data" Version="8.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.0-dev-02083" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0-dev-10359" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0-dev-00923" />
</ItemGroup>

</Project>
108 changes: 0 additions & 108 deletions BLART/Bot.cs

This file was deleted.

2 changes: 1 addition & 1 deletion BLART/Commands/RoleCommands/SyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ await RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCodes.Un
}

string dbConn =
$"Server=127.0.0.1;uid={Program.Config.SqlUser};pwd={Program.Config.SqlPassword};database={Program.Config.SqlDatabase};default command timeout=60";
$"Server={Program.Config.SqlServer};uid={Program.Config.SqlUser};pwd={Program.Config.SqlPassword};database={Program.Config.SqlDatabase};default command timeout=60";
MySqlConnection conn = new(dbConn);
conn.Open();
string readText = "SELECT * FROM `credits`";
Expand Down
59 changes: 36 additions & 23 deletions BLART/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,48 @@ public class Config
public ulong RedRoleId { get; set; }
public ulong BugReportId { get; set; }
public int TriggerLengthLimit { get; set; }
public ulong ContributorId { get; set; } = 668651927298375690;
public ulong ContributorId { get; set; }
public string NorthwoodApiKey { get; set; }
public ulong StaffChannelId { get; set; }
public string SqlUser { get; set; }
public string SqlPassword { get; set; }
public string SqlDatabase { get; set; }
public string SqlServer { get; set; }

public List<ulong> CreditRoleIds { get; set; } = new();
public List<ulong> CreditRoleIds { get; set; }

public static readonly Config Default = new()
public Config()
{
BotToken = string.Empty,
BotPrefix = "~",
DiscStaffId = 0,
SpamLimit = 10,
SpamTimeout = 5,
ChannelRentId = 0,
ChannelRentCatId = 0,
LogsId = 0,
Debug = false,
RedRoleId = 0,
BugReportId = 0,
TriggerLengthLimit = 200,
ContributorId = 0,
NorthwoodApiKey = string.Empty,
StaffChannelId = 0,
SqlUser = string.Empty,
SqlPassword = string.Empty,
SqlDatabase = string.Empty,
CreditRoleIds = new(),
};
BotToken = Environment.GetEnvironmentVariable("BOT_TOKEN")!;
BotPrefix = Environment.GetEnvironmentVariable("BOT_PREFIX")!;
DiscStaffId = ulong.Parse(Environment.GetEnvironmentVariable("DISC_STAFF_ID")!);
SpamLimit = int.Parse(Environment.GetEnvironmentVariable("SPAM_LIMIT")!);
SpamTimeout = int.Parse(Environment.GetEnvironmentVariable("SPAM_TIMEOUT")!);
ChannelRentId = ulong.Parse(Environment.GetEnvironmentVariable("CHANNEL_RENT_ID")!);
ChannelRentCatId = ulong.Parse(Environment.GetEnvironmentVariable("CHANNEL_RENT_CATEGORY_ID")!);
LogsId = ulong.Parse(Environment.GetEnvironmentVariable("LOGS_CHANNEL_ID")!);
Debug = bool.Parse(Environment.GetEnvironmentVariable("DEBUG")!);
RedRoleId = ulong.Parse(Environment.GetEnvironmentVariable("RED_ROLE_ID")!);
BugReportId = ulong.Parse(Environment.GetEnvironmentVariable("BUG_REPORT_CHANNEL_ID")!);
TriggerLengthLimit = int.Parse(Environment.GetEnvironmentVariable("LENGHT_LIMIT")!);
ContributorId = ulong.Parse(Environment.GetEnvironmentVariable("CONTRIBUTOR_ROLE_ID")!);
NorthwoodApiKey = Environment.GetEnvironmentVariable("NW_API_KEY")!;
StaffChannelId = ulong.Parse(Environment.GetEnvironmentVariable("STAFF_CHANNEL_ID")!);
SqlServer = Environment.GetEnvironmentVariable("DB_SERVER")!;
SqlUser = Environment.GetEnvironmentVariable("DB_USER")!;
SqlPassword = Environment.GetEnvironmentVariable("DB_PASSWORD")!;
SqlDatabase = Environment.GetEnvironmentVariable("DB_DATABASE")!;
CreditRoleIds = GetCreditRoleIds().ToList();
}

private static IEnumerable<ulong> GetCreditRoleIds()
{
var env = Environment.GetEnvironmentVariable("CREDIT_ROLE_IDS")!;
var roles = env.Split(',');
foreach (var role in roles)
{
if (ulong.TryParse(role, out ulong returnValue))
yield return returnValue;
}
}
}
17 changes: 17 additions & 0 deletions BLART/Db/BlartDb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BLART.Interfaces;
using LinqToDB;
using LinqToDB.Data;

namespace BLART.Db;

public class BlartDb : DataConnection
{
public BlartDb() : base(nameof(BlartDb)) { }

public ITable<Ban> Bans => this.GetTable<Ban>();
public ITable<PingTrigger> PingTriggers => this.GetTable<PingTrigger>();
public ITable<RedRole> RedRoles => this.GetTable<RedRole>();
public ITable<SelfAssignableRole> SelfAssignableRoles => this.GetTable<SelfAssignableRole>();
public ITable<Tag> Tags => this.GetTable<Tag>();
public ITable<Warn> Warns => this.GetTable<Warn>();
}
23 changes: 23 additions & 0 deletions BLART/Interfaces/Ban.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using LinqToDB;
using LinqToDB.Mapping;

namespace BLART.Interfaces;

[Table("bans")]
public class Ban : IDbTable
{
[Column("id"), PrimaryKey, Identity]
public ulong Id { get; set; }

[Column("user_id")]
public ulong UserId { get; set; }

[Column("staff_id")]
public ulong StaffId { get; set; }

[Column("reason", DataType = DataType.Text)]
public string Reason { get; set; } = null!;

[Column("issued_at")]
public DateTimeOffset IssuedAt { get; set; }
}
4 changes: 4 additions & 0 deletions BLART/Interfaces/IDbTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace BLART.Interfaces;

// Just to register tables more easily.
public interface IDbTable { }
14 changes: 14 additions & 0 deletions BLART/Interfaces/PingTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using LinqToDB;
using LinqToDB.Mapping;

namespace BLART.Interfaces;

[Table("ping_triggers")]
public class PingTrigger : IDbTable
{
[Column("user_id"), PrimaryKey]
public ulong UserId { get; set; }

[Column("message", DataType = DataType.Text)]
public string Message { get; set; } = null!;
}
23 changes: 23 additions & 0 deletions BLART/Interfaces/RedRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using LinqToDB;
using LinqToDB.Mapping;

namespace BLART.Interfaces;

[Table("red_roles")]
public class RedRole : IDbTable
{
[Column("id"), PrimaryKey, Identity]
public ulong Id { get; set; }

[Column("user_id")]
public ulong UserId { get; set; }

[Column("staff_id")]
public ulong StaffId { get; set; }

[Column("reason", DataType = DataType.Text)]
public string Reason { get; set; } = null!;

[Column("issued_at")]
public DateTimeOffset IssuedAt { get; set; }
}
10 changes: 10 additions & 0 deletions BLART/Interfaces/SelfAssignableRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using LinqToDB.Mapping;

namespace BLART.Interfaces;

[Table("self_assignable_roles")]
public class SelfAssignableRole : IDbTable
{
[Column("role_id"), PrimaryKey]
public ulong RoleId { get; set; }
}
17 changes: 17 additions & 0 deletions BLART/Interfaces/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using LinqToDB;
using LinqToDB.Mapping;

namespace BLART.Interfaces;

[Table("tags")]
public class Tag : IDbTable
{
[Column("name", DataType = DataType.Text), PrimaryKey]
public string Name { get; set; } = null!;

[Column("text", DataType = DataType.Text)]
public string Text { get; set; } = null!;

[Column("user_id")]
public ulong UserId { get; set; }
}
Loading