mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
38 lines
876 B
C#
38 lines
876 B
C#
using Telegram.Bot.Types;
|
|
using Telegram.Bot.Types.Enums;
|
|
using JetHerald.Services;
|
|
|
|
namespace JetHerald.Commands;
|
|
public class DeleteTopicCommand : IChatCommand
|
|
{
|
|
Db Db { get; }
|
|
|
|
public DeleteTopicCommand(Db db)
|
|
{
|
|
Db = db;
|
|
}
|
|
|
|
public async Task<string> Execute(CommandString cmd, Update update)
|
|
{
|
|
if (cmd.Parameters.Length < 1)
|
|
return null;
|
|
var msg = update.Message;
|
|
|
|
if (msg.Chat.Type != ChatType.Private)
|
|
return null;
|
|
|
|
string name = cmd.Parameters[0];
|
|
|
|
var user = await Db.GetUser(NamespacedId.Telegram(msg.From.Id));
|
|
|
|
if (user == null) return null;
|
|
|
|
var changed = await Db.DeleteTopic(name, user.UserId);
|
|
if (changed > 0)
|
|
return $"deleted {name} and all its subscriptions";
|
|
else
|
|
return $"invalid topic name";
|
|
}
|
|
}
|
|
|