[rules] Implement /rules and /setrules. DIsable build of arm images.

This commit is contained in:
West14
2022-01-18 21:36:47 +02:00
parent 9d2b0e5374
commit ffbb9dfee8
2 changed files with 22 additions and 24 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ jobs:
name: Build and push name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
platforms: linux/amd64,linux/arm64 platforms: linux/amd64
push: ${{ github.ref == 'refs/heads/dev' }} push: ${{ github.ref == 'refs/heads/dev' }}
tags: ${{ secrets.REGISTRY_URL }}/west/telegram-bot:latest, tags: ${{ secrets.REGISTRY_URL }}/west/telegram-bot:latest,
${{ secrets.REGISTRY_URL }}/west/telegram-bot:${{ steps.commit_sha.outputs.sha_short }} ${{ secrets.REGISTRY_URL }}/west/telegram-bot:${{ steps.commit_sha.outputs.sha_short }}
+21 -23
View File
@@ -4,45 +4,43 @@ using BotFramework.Enums;
using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Exceptions;
namespace West.TelegramBot.ChatManagement.Handler namespace West.TelegramBot.ChatManagement.Handler
{ {
internal partial class Rules : ManagementHandler internal class Rules : ManagementHandler
{ {
[Command(InChat.Public, "setrules", CommandParseMode.Both)] [Command(InChat.Public, "setrules", CommandParseMode.Both)]
public async Task HandleSetRules() public async Task HandleSetRules()
{ {
var replyToMessage = Message?.ReplyToMessage; var replyToMessage = Message?.ReplyToMessage;
var text = replyToMessage?.Text;
if (replyToMessage == null || text == null)
{
return;
}
//var entities = replyToMessage.Entities; if (replyToMessage == null || !await CanPunish()) return;
//if (entities != null)
//{
// //foreach (var entity in entities)
// //{
// // var entityText = text.Substring(entity.Offset, entity.Length);
// // text = text
// // .Remove(entity.Offset, entity.Length)
// // .Insert(entity.Offset)
// //}
//}
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
await Bot.SendTextMessageAsync(Chat, "tut bilo milo kruzi no on protiv"); opt.SetValue(replyToMessage.MessageId);
Db.MarkAsModified(opt);
} }
[Command(InChat.Public, "rules", CommandParseMode.Both)] [Command(InChat.Public, "rules", CommandParseMode.Both)]
public async Task HandleRules() public async Task HandleRules()
{ {
var opt = Db.UserValues.FindOrCreateOption(Chat.Id, "rules"); var opt = await Db.UserValues.FindOption(Chat.Id, "rulesMsgId");
if (opt == null)
{
return;
}
try
{
await Bot.CopyMessageAsync(Chat.Id, Chat.Id, opt.GetValue<int>());
}
catch (ApiRequestException)
{
Db.MarkAsDeleted(opt);
}
} }
public Rules(CoreContext db) : base(db) public Rules(CoreContext db) : base(db) {}
{
}
} }
} }