Merge pull request #3 from CrazyHackGUT/feature/rules

/rules & /setrules commands
This commit is contained in:
Kruzya
2022-01-18 22:42:29 +03:00
committed by GitHub
2 changed files with 47 additions and 1 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 }}
+46
View File
@@ -0,0 +1,46 @@
using System.Threading.Tasks;
using BotFramework.Attributes;
using BotFramework.Enums;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
using Telegram.Bot.Exceptions;
namespace West.TelegramBot.ChatManagement.Handler
{
internal class Rules : ManagementHandler
{
[Command(InChat.Public, "setrules", CommandParseMode.Both)]
public async Task HandleSetRules()
{
var replyToMessage = Message?.ReplyToMessage;
if (replyToMessage == null || !await CanPunish()) return;
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
opt.SetValue(replyToMessage.MessageId);
Db.MarkAsModified(opt);
}
[Command(InChat.Public, "rules", CommandParseMode.Both)]
public async Task HandleRules()
{
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) {}
}
}