2020-02-01 13:03:02 +01:00
using System.Threading.Tasks ;
using PluralKit.Core ;
2020-02-12 15:16:19 +01:00
namespace PluralKit.Bot
2020-02-01 13:03:02 +01:00
{
public class System
{
2020-08-29 13:46:27 +02:00
private readonly EmbedService _embeds ;
private readonly IDatabase _db ;
private readonly ModelRepository _repo ;
2021-08-27 11:03:47 -04:00
2020-08-29 13:46:27 +02:00
public System ( EmbedService embeds , IDatabase db , ModelRepository repo )
2020-02-01 13:03:02 +01:00
{
_embeds = embeds ;
2020-08-29 13:46:27 +02:00
_db = db ;
_repo = repo ;
2020-02-01 13:03:02 +01:00
}
2021-08-27 11:03:47 -04:00
public async Task Query ( Context ctx , PKSystem system )
{
2020-02-01 13:03:02 +01:00
if ( system = = null ) throw Errors . NoSystemError ;
2020-09-12 18:10:37 -04:00
await ctx . Reply ( embed : await _embeds . CreateSystemEmbed ( ctx , system , ctx . LookupContextFor ( system ) ) ) ;
2020-02-01 13:03:02 +01:00
}
2020-04-24 15:50:28 -04:00
2020-02-01 13:03:02 +01:00
public async Task New ( Context ctx )
{
ctx . CheckNoSystem ( ) ;
2020-08-11 22:05:27 +02:00
var systemName = ctx . RemainderOrNull ( ) ;
if ( systemName ! = null & & systemName . Length > Limits . MaxSystemNameLength )
2021-09-13 01:13:57 -04:00
throw Errors . StringTooLongError ( "System name" , systemName . Length , Limits . MaxSystemNameLength ) ;
2020-08-29 13:46:27 +02:00
2021-09-29 21:51:38 -04:00
var system = await _repo . CreateSystem ( systemName ) ;
await _repo . AddAccount ( system . Id , ctx . Author . Id ) ;
2021-08-27 11:03:47 -04:00
2020-08-29 13:46:27 +02:00
// TODO: better message, perhaps embed like in groups?
2020-02-09 22:35:16 +01:00
await ctx . Reply ( $"{Emojis.Success} Your system has been created. Type `pk;system` to view it, and type `pk;system help` for more information about commands you can use now. Now that you have that set up, check out the getting started guide on setting up members and proxies: <https://pluralkit.me/start>" ) ;
2020-02-01 13:03:02 +01:00
}
}
2021-08-27 11:03:47 -04:00
}