Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 11, 2024
1 parent f05f6b4 commit 56ab2f6
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 6 deletions.
48 changes: 47 additions & 1 deletion XinjingdailyBot.Infrastructure/Configs/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,51 @@
namespace XinjingdailyBot.Infrastructure.Options;
public sealed record BotConfig : IXjbConfig
{
public static string? SectionName => "Bot";
static string? IXjbConfig.SectionName => "Bot";

/// <summary>
/// Telegram Api地址
/// </summary>
public string? BaseUrl { get; set; }
/// <summary>
/// 机器人Token
/// </summary>
public List<string?> BotTokens { get; set; }
/// <summary>
/// 机器人Token
/// </summary>
public string BotToken { get; set; }
/// <summary>
/// 代理链接, 默认 null
/// </summary>
public string? Proxy { get; set; }
/// <summary>
/// 忽略机器人离线时的Update
/// </summary>
public bool ThrowPendingUpdates { get; set; }
/// <summary>
/// 自动退出未在配置文件中定义的群组和频道, 默认 false
/// </summary>
public bool AutoLeaveOtherGroup { get; set; }
/// <summary>
/// 超级管理员(覆盖数据库配置)
/// </summary>
public HashSet<long>? SuperAdmins { get; set; }

/// <summary>
/// 启用定时发布
/// </summary>
public bool EnablePlanPost { get; set; }
/// <summary>
/// 二级菜单
/// </summary>
public bool PostSecondMenu { get; set; }
/// <summary>
/// 文本稿件发布时是否启用链接预览
/// </summary>
public bool EnableWebPagePreview { get; set; }
/// <summary>
/// 纯链接投稿显示警告
/// </summary>
public bool WarnRawLinkPost { get; set; }
}
53 changes: 53 additions & 0 deletions XinjingdailyBot.Infrastructure/Configs/ChannelOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using DsNext.Infrastructure.Options;

namespace XinjingdailyBot.Infrastructure.Options;
public sealed record ChannelOption : IXjbConfig
{
static string? IXjbConfig.SectionName => "Channel";

/// <summary>
/// 审核群组
/// </summary>
public string ReviewGroup { get; set; } = "";
/// <summary>
/// 日志频道
/// </summary>
public string LogChannel { get; set; } = "";
/// <summary>
/// 是否使用审核日志模式
/// 启用: 审核后在审核群直接删除消息, 审核记录发送至审核日志频道
/// 禁用: 审核后再审核群保留消息记录, 审核日志频道不使用
/// </summary>
public bool UseReviewLogMode { get; set; }
/// <summary>
/// 频道评论区群组
/// </summary>
public string CommentGroup { get; set; } = "";
/// <summary>
/// 闲聊区群组
/// </summary>
public string SubGroup { get; set; } = "";
/// <summary>
/// 通过频道
/// </summary>
public string AcceptChannel { get; set; } = "";
/// <summary>
/// 第二频道
/// </summary>
public string SecondChannel { get; set; } = "";
/// <summary>
/// 第二频道评论区
/// </summary>
public string SecondCommentGroup { get; set; } = "";
/// <summary>
/// 拒稿频道
/// </summary>
public string RejectChannel { get; set; } = "";
/// <summary>
/// 管理日志频道
/// 用于存储封禁/解封日志
/// </summary>
public string AdminLogChannel { get; set; } = "";


}
49 changes: 49 additions & 0 deletions XinjingdailyBot.Infrastructure/Configs/DatabaseConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DsNext.Infrastructure.Options;

namespace XinjingdailyBot.Infrastructure.Options;
public sealed record DatabaseConfig : IXjbConfig
{
static string? IXjbConfig.SectionName => "Database";

/// <summary>
/// 是否生成数据库字段(数据库结构变动时需要打开), 默认 false
/// </summary>
public bool Generate { get; set; }
/// <summary>
/// 打印SQL日志
/// </summary>
public bool LogSQL { get; set; }
/// <summary>
/// 是否使用MySQL数据库, true:MySQL, false:SQLite
/// </summary>
[Obsolete("使用DbType代替")]
public bool UseMySQL { get; set; }
/// <summary>
/// 数据库类型
/// </summary>
public string? DbType { get; set; }
/// <summary>
/// 数据库连接字符串(DbType选Custom时生效)
/// </summary>
public string? DbConnectionString { get; set; }
/// <summary>
/// MySQL主机IP
/// </summary>
public string? DbHost { get; set; }
/// <summary>
/// MySQL主机端口
/// </summary>
public uint DbPort { get; set; }
/// <summary>
/// MySQL数据库名称
/// </summary>
public string? DbName { get; set; }
/// <summary>
/// MySQL用户名
/// </summary>
public string? DbUser { get; set; }
/// <summary>
/// MySQL密码
/// </summary>
public string? DbPassword { get; set; }
}
3 changes: 3 additions & 0 deletions XinjingdailyBot.Infrastructure/Configs/IXjbConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace DsNext.Infrastructure.Options;
public interface IXjbConfig
{
/// <summary>
/// 节名称, 留空使用根节点
/// </summary>
abstract static string? SectionName { get; }
}
8 changes: 7 additions & 1 deletion XinjingdailyBot.Infrastructure/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public static class Utils
/// </summary>
private static readonly Assembly _assembly = Assembly.GetExecutingAssembly();

public static string AppDir => Directory.GetParent(_assembly.Location).FullName;
/// <summary>
/// 可执行文件所在目录
/// </summary>
public static string AppDir => Directory.GetParent(_assembly.Location)?.FullName ?? ".";
/// <summary>
/// 可执行文件路径
/// </summary>
public static string AppPath => _assembly.Location;

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion XinjingdailyBot.WebAPI/Extensions/OptionsExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DsNext.Infrastructure.Options;
using XinjingdailyBot.Infrastructure;
using XinjingdailyBot.Infrastructure.Options;

namespace XinjingdailyBot.WebAPI.Extensions;
Expand All @@ -16,7 +17,7 @@ public static void AddCustomJsonFiles(this WebApplicationBuilder builder)
{
var config = builder.Configuration;

var basePath = Path.Combine(AppContext.BaseDirectory, "config");
var basePath = Path.Combine(Utils.AppDir, "config");
config.SetBasePath(basePath);

config.AddJsonFile("log.json", true, true);
Expand Down
1 change: 0 additions & 1 deletion XinjingdailyBot.WebAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"XinjingdailyBot.WebAPI": {
"commandName": "Project",
"workingDirectory": "bin",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
4 changes: 2 additions & 2 deletions XinjingdailyBot.WebAPI/config/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"DbConnectionString": null,
"DbHost": "10.10.0.3",
"DbPort": 3306,
"DbName": "sas",
"DbName": "xjb_bot",
"DbUser": "root",
"DbPassword": "qgd9qH$QXZ&Lt&$KbhJ7fnRgy9n4Fv"
"DbPassword": "123456"
}
}

0 comments on commit 56ab2f6

Please sign in to comment.