using Tesses.WebServer;
namespace Tesses.Chatr.Server
{
public class Permissions
{
///
/// Can the bot send messages to other users
///
public bool CanSendMessagesToOtherPeople {get;set;}
///
/// Can other bots receive messages from this bot
///
public bool OthersCanReceiveMessages {get;set;}
///
/// Can this bot send notifications
///
public bool CanSendNotifications {get;set;}
///
///Bot Can pull data from share target
///
public bool CanGetFromShareTarget {get;set;}
///
///Bot Can Receive Messages
///
public bool CanGetMessages { get; set; }
public void SetPermissionsFromForm(ServerContext ctx)
{
CanSendMessagesToOtherPeople=GetPermissionValue(ctx,"other_people");
OthersCanReceiveMessages=GetPermissionValue(ctx,"bot2bot");
CanSendNotifications=GetPermissionValue(ctx,"notification");
CanGetFromShareTarget=GetPermissionValue(ctx,"share_target");
CanGetMessages=GetPermissionValue(ctx,"recv_msg");
}
private bool GetPermissionValue(ServerContext ctx,string key)
{
string res;
if(ctx.QueryParams.TryGetFirst(key,out res))
{
return res=="on";
}
return false;
}
}
}