Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 8, 2023
1 parent 5246c48 commit 0e8c60e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 23 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>2.1.1.2</Version>
<Version>2.1.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@

`2.x` 后, 可选 `Sqlite` 作为数据库实现, 在配置文件的 `Database` 节设置 `UseMySQL``false` 即可

`2.0.18.x` 后, 新增自定义标签支持, 之前版本的投稿数据请使用命令 `/mergepost` 进行一次性转换, 否则标签可能不能正确识别
`2.0.18.x` 后, 新增自定义标签支持, 之前版本的投稿数据请使用命令 `/fixpost` 进行一次性转换, 否则标签可能不能正确识别

`2.1.x.x` 后, 使用了新的稿件表, 之前版本的投稿数据请使用命令 `/mergepost` 进行一次性转换, 否则旧的投稿无法识别

### 配置说明

Expand Down
13 changes: 10 additions & 3 deletions XinjingdailyBot.Command/AdminCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using SqlSugar;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -1430,9 +1431,15 @@ public async Task QResponseNuke(Users dbUser, CallbackQuery callbackQuery, strin
[TextCmd("TOKEN", EUserRights.AdminCmd, Description = "获取WebAPI密钥")]
public async Task ResponseToken(Users dbUser, Message message)
{
var token = await _userTokenService.GenerateNewUserToken(dbUser);

await _botClient.SendCommandReply(token.APIToken.ToString(), message, false);
if (message.Chat.Type != ChatType.Private)
{
await _botClient.SendCommandReply("该命令仅限私聊使用", message, false);
}
else
{
var token = await _userTokenService.GenerateNewUserToken(dbUser);
await _botClient.SendCommandReply(token.APIToken.ToString(), message, false);
}
}

/// <summary>
Expand Down
27 changes: 25 additions & 2 deletions XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using XinjingdailyBot.Infrastructure.Extensions;
using XinjingdailyBot.Model.Models;
using XinjingdailyBot.WebAPI.IPC.Requests;
using XinjingdailyBot.WebAPI.IPC.Responses;

Expand Down Expand Up @@ -28,6 +27,30 @@ public PostController(
_httpContextAccessor = httpContextAccessor;
}

/// <summary>
/// 连接测试
/// </summary>
/// <returns></returns>
[HttpGet("[action]")]
[HttpPost("[action]")]
public ActionResult<GenericResponse<TestTokenResponse>> TestToken()
{
var user = _httpContextAccessor.GetUser();

var response = new GenericResponse<TestTokenResponse> {
Code = 0,
Message = "成功",
Result = new TestTokenResponse {
UID = user.Id,
UserID = user.UserID,
UserName = user.UserName,
NickName = user.FullName,
}
};

return Ok(response);
}

/// <summary>
/// 创建稿件
/// </summary>
Expand All @@ -51,6 +74,6 @@ public async Task<ActionResult<GenericResponse<CreatePostResponse>>> CreatePost(
}
};

return response;
return Ok(response);
}
}
23 changes: 7 additions & 16 deletions XinjingdailyBot.WebAPI/IPC/Requests/CreatePostRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed record CreatePostRequest
/// </summary>
[MaxLength(2000)]
[DefaultValue("")]
public string Text { get; set; } = "";
public string? Text { get; set; }
/// <summary>
/// 匿名投稿
/// </summary>
Expand All @@ -25,45 +25,36 @@ public sealed record CreatePostRequest
/// </summary>
public IFormFileCollection? Media { get; set; }
/// <summary>
/// 转发频道来源
/// </summary>
[AllowNull]
public FromData? From { get; set; }
/// <summary>
/// 消息类型
/// </summary>
[DefaultValue(0)]
[DefaultValue(MessageType.Unknown)]
public MessageType PostType { get; set; } = MessageType.Unknown;
/// <summary>
/// 是否启用遮罩
/// </summary>
[DefaultValue(false)]
public bool HasSpoiler { get; set; }
}

/// <summary>
/// 转发来源
/// </summary>
public sealed record FromData
{
/// <summary>
/// 频道ID
/// </summary>
[DefaultValue(-1)]
public long ChannelID { get; set; }
public long ChannelID { get; set; } = -1;
/// <summary>
/// 频道ID @
/// </summary>
[DefaultValue("")]
public string ChannelName { get; set; } = "";
public string? ChannelName { get; set; }
/// <summary>
/// 频道名称
/// </summary>
[DefaultValue("")]
public string ChannelTitle { get; set; } = "";
public string? ChannelTitle { get; set; }
/// <summary>
/// 转发消息ID
/// </summary>
[DefaultValue(-1)]
public long ChannelMsgID { get; set; } = -1;
}


14 changes: 14 additions & 0 deletions XinjingdailyBot.WebAPI/IPC/Responses/TestTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Telegram.Bot.Types.Enums;

namespace XinjingdailyBot.WebAPI.IPC.Responses;

/// <summary>
/// 连接测试响应
/// </summary>
public sealed record TestTokenResponse
{
public string UserName { get; set; }
public long UserID { get; set; }
public int UID { get; set; }
public string NickName { get; set; }
}

0 comments on commit 0e8c60e

Please sign in to comment.