mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
"/at create" command
This commit is contained in:
parent
84a96745c9
commit
609e4c018f
@ -154,7 +154,7 @@ namespace JetKarmaBot.Commands
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return awardType.Name;
|
return awardType.NominativeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ namespace JetKarmaBot.Commands
|
|||||||
{
|
{
|
||||||
Router = r;
|
Router = r;
|
||||||
Router.SuperCommand = "at";
|
Router.SuperCommand = "at";
|
||||||
r.Add(c.GetInstance<AwardTypeManage.TestCommand>());
|
r.Add(c.GetInstance<AwardTypeManage.CreateCommand>());
|
||||||
r.Add(c.GetInstance<HelpCommand>());
|
r.Add(c.GetInstance<HelpCommand>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
101
JetKarmaBot/Commands/AwardTypeManage/CreateCommand.cs
Normal file
101
JetKarmaBot/Commands/AwardTypeManage/CreateCommand.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JetKarmaBot.Models;
|
||||||
|
using JetKarmaBot.Services;
|
||||||
|
using Perfusion;
|
||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Args;
|
||||||
|
|
||||||
|
namespace JetKarmaBot.Commands.AwardTypeManage
|
||||||
|
{
|
||||||
|
public class CreateCommand : IChatCommand
|
||||||
|
{
|
||||||
|
public IReadOnlyCollection<string> Names => new[] { "create" };
|
||||||
|
|
||||||
|
public string Description => "Create an award type.";
|
||||||
|
|
||||||
|
public string DescriptionID => "jetkarmabot.at.create.help";
|
||||||
|
[Inject] TelegramBotClient Client { get; set; }
|
||||||
|
[Inject] public KarmaContextFactory Db { get; set; }
|
||||||
|
[Inject] public Localization Locale { get; set; }
|
||||||
|
|
||||||
|
public IReadOnlyCollection<ChatCommandArgument> Arguments => new[] {
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="cmdname",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="Name used when awarding to user.",
|
||||||
|
DescriptionID="jetkarmabot.at.create.cmdnamehelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="nomname",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="Name used when in currencies list.",
|
||||||
|
DescriptionID="jetkarmabot.at.create.nomnamehelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="accname",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="Name used in award message",
|
||||||
|
DescriptionID="jetkarmabot.at.create.accnamehelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="symbol",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="Symbol of the award type.",
|
||||||
|
DescriptionID="jetkarmabot.at.create.symbolhelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="desc",
|
||||||
|
Required=false,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="Description of the award type.",
|
||||||
|
DescriptionID="jetkarmabot.at.create.symbolhelp"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public async Task<bool> Execute(ICommandRouter route, CommandString cmd, MessageEventArgs args)
|
||||||
|
{
|
||||||
|
using (var db = Db.GetContext())
|
||||||
|
{
|
||||||
|
var currentLocale = Locale[(await db.Chats.FindAsync(args.Message.Chat.Id)).Locale];
|
||||||
|
if (cmd.Parameters.Length < 4 || cmd.Parameters.Length > 5)
|
||||||
|
{
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.create.errarg"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
string cmdname = cmd.Parameters[0];
|
||||||
|
string nomname = cmd.Parameters[1];
|
||||||
|
string accname = cmd.Parameters[2];
|
||||||
|
string symbol = cmd.Parameters[3];
|
||||||
|
string desc = cmd.Parameters.Length == 4 ? "" : cmd.Parameters[4];
|
||||||
|
|
||||||
|
|
||||||
|
await db.AwardTypes.AddAsync(new AwardType()
|
||||||
|
{
|
||||||
|
CommandName = cmdname,
|
||||||
|
NominativeName = nomname,
|
||||||
|
AccusativeName = accname,
|
||||||
|
Symbol = symbol,
|
||||||
|
Description = desc,
|
||||||
|
ChatId = args.Message.Chat.Id
|
||||||
|
});
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.create.success"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Args;
|
|
||||||
|
|
||||||
namespace JetKarmaBot.Commands.AwardTypeManage
|
|
||||||
{
|
|
||||||
public class TestCommand : IChatCommand
|
|
||||||
{
|
|
||||||
public IReadOnlyCollection<string> Names => new[] { "test" };
|
|
||||||
|
|
||||||
public string Description => "test";
|
|
||||||
|
|
||||||
public string DescriptionID => "test";
|
|
||||||
|
|
||||||
public IReadOnlyCollection<ChatCommandArgument> Arguments => Array.Empty<ChatCommandArgument>();
|
|
||||||
|
|
||||||
public Task<bool> Execute(ICommandRouter route, CommandString cmd, MessageEventArgs messageEventArgs)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -31,7 +31,7 @@ namespace JetKarmaBot.Commands
|
|||||||
string resp = currentLocale["jetkarmabot.currencies.listtext"] + "\n"
|
string resp = currentLocale["jetkarmabot.currencies.listtext"] + "\n"
|
||||||
+ $"★ (star) <i>{currentLocale["jetkarmabot.star.nominative"]}</i>\n"
|
+ $"★ (star) <i>{currentLocale["jetkarmabot.star.nominative"]}</i>\n"
|
||||||
+ string.Join("\n",
|
+ string.Join("\n",
|
||||||
(await db.AwardTypes.ToListAsync()).Select(x => $"{x.Symbol} ({x.CommandName}) <i>{x.Name}</i>"));
|
(await db.AwardTypes.ToListAsync()).Select(x => $"{x.Symbol} ({x.CommandName}) <i>{x.NominativeName}</i>"));
|
||||||
await Client.SendTextMessageAsync(
|
await Client.SendTextMessageAsync(
|
||||||
args.Message.Chat.Id,
|
args.Message.Chat.Id,
|
||||||
resp,
|
resp,
|
||||||
|
|||||||
@ -14,7 +14,8 @@ namespace JetKarmaBot.Models
|
|||||||
public sbyte AwardTypeId { get; set; }
|
public sbyte AwardTypeId { get; set; }
|
||||||
public string CommandName { get; set; }
|
public string CommandName { get; set; }
|
||||||
public long ChatId { get; set; }
|
public long ChatId { get; set; }
|
||||||
public string Name { get; set; }
|
[Column("name")]
|
||||||
|
public string NominativeName { get; set; }
|
||||||
[Column("accname")]
|
[Column("accname")]
|
||||||
public string AccusativeName { get; set; }
|
public string AccusativeName { get; set; }
|
||||||
public string Symbol { get; set; }
|
public string Symbol { get; set; }
|
||||||
|
|||||||
@ -130,7 +130,7 @@ namespace JetKarmaBot.Models
|
|||||||
.HasColumnName("description")
|
.HasColumnName("description")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
entity.Property(e => e.Name)
|
entity.Property(e => e.NominativeName)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnName("name")
|
.HasColumnName("name")
|
||||||
.HasColumnType("varchar(32)");
|
.HasColumnType("varchar(32)");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user