chatr/ChatrServer/Chatr/Permissions.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2022-08-24 11:34:56 +00:00
using Tesses.WebServer;
namespace Tesses.Chatr.Server
{
public class Permissions
{
///<summary>
/// Can the bot send messages to other users
///</summary>
public bool CanSendMessagesToOtherPeople {get;set;}
///<summary>
/// Can other bots receive messages from this bot
///</summary>
public bool OthersCanReceiveMessages {get;set;}
///<summary>
/// Can this bot send notifications
///</summary>
public bool CanSendNotifications {get;set;}
///<summary>
///Bot Can pull data from share target
///</summary>
public bool CanGetFromShareTarget {get;set;}
///<summary>
///Bot Can Receive Messages
///</summary>
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;
}
}
}