Skip to content

Commit 6681d71

Browse files
committed
finished documentation & added some stuff
[ + ] Added Readme docs [ + ] Added Object docs [ + ] Added Attributes docs [ + ] Added examples [ # ] InteractionBase.Respond will now return Task<Amino.Objects.Message> instead of nothing [ + ] Added InteractionBase.RespondWithFile [ + ] Added InteractionBase.RespondWithSticker [ + ] Added InteractionBase.RespondWithEmbed
1 parent 8467db5 commit 6681d71

8 files changed

Lines changed: 261 additions & 3 deletions

File tree

Amino.NET.Interactions/Amino.NET.Interactions.csproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,40 @@
44
<TargetFramework>net7.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<Authors>FabioTheeFox</Authors>
8+
<Company>FabiDev</Company>
9+
<Description>A simple framework for Amino chatbots built on Amino.NET</Description>
10+
<PackageId>Amino.NET.Interactions</PackageId>
11+
<Title>Amino.NET.Interactions</Title>
12+
<Version>1.0.0</Version>
13+
<Product>Amino.NET.Interactions</Product>
14+
<Copyright>FabioTheFox</Copyright>
15+
<PackageIcon>Amino.Net-Logo-V2.png</PackageIcon>
16+
<PackageReadmeFile>README.md</PackageReadmeFile>
17+
<RepositoryUrl>https://github.com/Amino-NET-Group/Amino.NET.Interactions</RepositoryUrl>
18+
<RepositoryType>GIT</RepositoryType>
19+
<PackageTags>Amino, Aminoapps, Amino.NET, rest, api, framework, Amino.NET.Interactions, Interactions</PackageTags>
20+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
21+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
22+
<IncludeSymbols>False</IncludeSymbols>
723
</PropertyGroup>
824

25+
<ItemGroup>
26+
<None Include="..\README.md">
27+
<Pack>True</Pack>
28+
<PackagePath>\</PackagePath>
29+
</None>
30+
</ItemGroup>
31+
932
<ItemGroup>
1033
<PackageReference Include="Amino.NET" Version="1.6.0" />
1134
</ItemGroup>
1235

36+
<ItemGroup>
37+
<None Update="Media\Amino.Net-Logo-V2.png">
38+
<Pack>True</Pack>
39+
<PackagePath>\</PackagePath>
40+
</None>
41+
</ItemGroup>
42+
1343
</Project>

Amino.NET.Interactions/InteractionBase.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,39 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7-
7+
using Amino;
8+
using System.Security.Cryptography.X509Certificates;
89
namespace Amino.Interactions
910
{
1011
public class InteractionBase
1112
{
1213

1314

14-
public Task Respond(Interaction context, string message, bool asReply)
15+
public Task<Amino.Objects.Message> Respond(Interaction context, string message, bool asReply = true)
16+
{
17+
SubClient subClient = new SubClient(context.AminoClient, context.Message.communityId.ToString());
18+
var ReturnMessage = subClient.send_message(message, context.InteractionChatId, replyTo: asReply ? context.Message.messageId : null);
19+
return Task.FromResult(ReturnMessage);
20+
}
21+
22+
public Task RespondWithFile(Interaction context, byte[] file, Amino.Types.upload_File_Types type = Types.upload_File_Types.Image)
23+
{
24+
SubClient subClient = new SubClient(context.AminoClient, context.Message.communityId.ToString());
25+
subClient.send_file_message(context.InteractionChatId, file, type);
26+
return Task.CompletedTask;
27+
}
28+
29+
public Task RespondWithSticker(Interaction context, string stickerId)
30+
{
31+
SubClient subClient = new SubClient(context.AminoClient, context.Message.communityId.ToString());
32+
subClient.send_sticker(context.InteractionChatId, stickerId);
33+
return Task.CompletedTask;
34+
}
35+
36+
public Task RespondWithEmbed(Interaction context, string content, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null)
1537
{
38+
SubClient subClient = new SubClient(context.AminoClient, context.Message.communityId.ToString());
39+
subClient.send_embed(context.InteractionChatId, content, embedId, embedLink, embedTitle, embedContent, embedImage);
1640
return Task.CompletedTask;
1741
}
1842

Amino.NET.Interactions/InteractionsClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public InteractionsClient(Amino.Client client)
5959

6060
private void HandleMessageSocket(Amino.Objects.Message message)
6161
{
62+
if(message.Author.userId == this.AminoClient.userID && IgnoreSelf) { return; }
6263
if (message.content.StartsWith(InteractionPrefix))
6364
{
6465
if (InteractionModules.ContainsKey(message.content.Substring(InteractionPrefix.Length).Split(" ")[0]))
152 KB
Loading

Attributes.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Amino.NET.Interactions Attributes
2+
Attributes in Amino.NET.Interactions are used to define your commands and set properties for it, here you will see all attributes along with what they are for
3+
All Attributes are located in the **Amino.Interactions.Attributes** namespace.
4+
5+
## Command
6+
The Command attribute is the Attribute that is defining that you want a function to be a command, note that this Attribute **is required** for every command.
7+
| Value | DataType | Description | Is Required |
8+
|-------|----------|-------------|-------------|
9+
| commandName | string | The name you want to give to the command | Yes |
10+
| commandDescription | string | A Description you can give to this command, it _could_ be used to generate help commands and such as you can easily fetch all Command Modules | No |
11+
| CommunityId | string | The Community ID you want to lock your command to | No
12+
13+
## EnabledInDms
14+
The EnabledInDms attribute will decide if your command can be used in DMs and or DM Group chats, this Attribute **is not** required to make a command.
15+
| Values | DataType | Description | Is required |
16+
|--------|----------|-------------|-------------|
17+
| isEnabledInDms | bool | The boolean value that decides if the command is availab in DMs | Yes
18+
19+
## PermissionGroup
20+
The PermissionGroup Attribute is used to set the required permission level for your command without you needing to do extra handling for it, it contains an **enum** that you **will need** so make sure to get it from its class **Amino.Interactions.Attributes.PermissionGroup.PermissionGroups**, this Attribute **is not** required to make your command work.
21+
| Values | DataType | Description | Is Required |
22+
|--------|----------|-------------|-------------|
23+
| permisionGroup | PermissionGroups | The permission group you set to be required for your command | Yes

Objects.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Amino.NET.Interaction Objects Guide
2+
This file will contain all (public) information about Objects and Clients you will use
3+
Note that some Parameters have default values, they will be displayed _like this_
4+
5+
## InteractionsClient
6+
| Values | DataType | Description | Default |
7+
|--------|----------|-------------|---------|
8+
| InteractionModules| Dictionary<string, [InteractionModule](#interactionmodule)> | The internal "database" of all registred modules
9+
|InteractionQueue | Queue<[Interaction](#interaction)>| A list of upcoming Interactions, not used if AutoHandleInteractions isn't marked as `true`
10+
| LogLevels | enum | An enum collection of the available LogLevels
11+
| InteractionCooldown | int | The cooldown used in automatic interaction handling | 2000
12+
| InteractionPrefix | string | The prefix of your commands | /
13+
| IgnoreSelf | bool | Determines if the bot should ignore its own actions | true
14+
| LogLevel | LogLevels | The desired LogLevel for that InteractionsClient instance | LogLevels.None
15+
| AutoHandleInteractions | bool | Determines if Interactions should be automatically handled | false
16+
| InteractionCreated | Action<[Interaction](#interaction)> | The event that fires when an Interaction is created
17+
| Log | Action<[LogMessage](#logmessage)> | The event that fires when a Log message is availabe
18+
19+
## InteractionsClient Functions
20+
| Usage | Description | Return |
21+
|-------|-------------|--------|
22+
| InteractionsClient(Amino.Client) | The constructor for your InteractionsClient, it will initiate all important things needed
23+
| RegisterModule<T\>() | This function will allow you to register an Interactions Module, please see [The general guide](./README.md) to see what makes a valid module
24+
| RegisterModules(Assembly) | This function will register all modules of the given Assembly, please see [The general guide](./README.md) to see what makes a valid module
25+
| HandleInteraction([Interaction](#interaction)) | The function used to redirect your interactions to the proper functions.
26+
27+
## InteractionBase Functions
28+
| Usage | Description | Return |
29+
|-------|-------------|--------|
30+
| Respond([Interaction](#interaction), string, string, _bool_) | The function to respond to an Interaction using a normal message | Task<Amino.Objects.Message>
31+
| RespondWithFile([Interaction](#interaction), byte[], Amino.Types.upload_file_types) | A function to respond to an Interaction with a file
32+
| RespondWithSticker([Interaction](#interaction), string) | A function that responds to an Interaction using a Sticker
33+
| RespondWithEmbed([Interaction](#interaction), _string_, _string_, _string_, _string_, _string_, _byte[]_) | A function that responds to an Interaction using an Embed
34+
35+
## LogMessage
36+
| Values | DataType | Description | Default |
37+
|--------|----------|-------------|---------|
38+
| Message | string | The message of the LogMessage |
39+
| Timestamp | long | The UNIX timestamp of the LogMessage |
40+
| LogLevel | [LogLevels](#interactionsclient) | The LogLevel of the LogMessage |
41+
42+
## InteractionModule
43+
| Values | DataType | Description | Default |
44+
|--------|----------|-------------|---------|
45+
| ModuleCommandName | string | The name of the command|
46+
| ModuleCommandDescription | string | The description of your command module |
47+
| ModuleCommandCommunity | int? | The community ID you have locked your command module to |
48+
| ModuleInteractionBase | [InteractionBase](#interactionbase-functions) | The base interaction class of this Module |
49+
| ModuleCommandEnabledInDms | bool | The value that decides if your module is available in DMs | true
50+
| ModulePermissionGroup | PermissionGroups | The required user Permission to use this command module | PermissionGroups.All
51+
| ModuleCommandParameters | List<(string, bool)> | A List of Parameters of this module, string is for parameter Type and bool decides if the parameter is optional or not | new List<(string, bool)>
52+
| ModuleInteractionMethod | InteractionMethodDelegate | The function linked to this module
53+
54+
## Interaction
55+
| Values | DataType | Description | Default |
56+
|--------|----------|-------------|---------|
57+
| InteractionChatId | string? | The Chat ID the Interaction has taken place in
58+
| InteractionName | string? | The name of the module that is getting targeted
59+
| AminoClient | Amino.Client | The Amino Client the Interaction has happened with
60+
| Message | Amino.Objects.Message | The Message object of the Interaction
61+
| InteractionTimestamp | long | The UNIX Timestamp of the Interaction
62+
| InteractionId | string? | A Unique identifier for this Interaction
63+
| InteractionParameters | List< string > | A list of parameters given in the Interaction | new List< string >
64+
| InteractionBaseModule | [InteractionModule](#interactionmodule) | The InteractionModule the current Interaction is linked to

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# Amino.NET.Interactions
1+
# Amino.NET.Interactions
2+
The official Amino.NET Framework made for chatbots!
3+
# What is this framework about?
4+
Making chatbots on Amino has always ben quite a hassle, with the Amino.NET.Interactions framework this has never been easier!
5+
6+
## Extras & Credits
7+
- This C# library is based on [Amino.NET](https://github.com/Amino-NET-Group/Amino.NET) and will therefore include it as a dependency, in case anything on this Library breaks consider updating Amino.NET to the latest stable (or dev) version, if this does not fix your issue, open an issue on github and or [join our community Discord Server](https://discord.gg/qyv8P2gegK)
8+
- If you find a bug or have an idea you'd like to see in this project, please open an issue for it or join our community discord, alternatively you can always make a pull request if you'd like to contribute to the development of it
9+
- Sometimes the documentation is not always up to date, we are aware of it and will fix it over time
10+
- Amino.NET Group / Amino Scripting group and its sub parts do not take any responsibility for any harm being done using this framework, as it is free and **open source**, therefore we can not prevent any harm done.
11+
- This is a non-profit project, however if you do want to us and our work you can check the Sponsor options of this repository, alternatively you can [check out our Ko-Fi!](https://ko-fi.com/fabiothefox)
12+
## Important Notice
13+
By using this library you agree that you are aware of the fact that you are breaking the App services Terms of Service - as Team Amino strictly forbids the use of any sort of third party software / scripting to gain an advantage over other members, any activity by third party tools found by Team Amino may result in your account getting banned from their services!
14+
## How to install
15+
You can install Amino.NET.Interactions [on NuGet](https://www.nuget.org) and in any NuGet package manager of your choice!
16+
## Quick Links
17+
- [General idea and setup](#where-to-start)
18+
- [Objects and Values](./Objects.md)
19+
- [Attributes Guide](./Attributes.md)
20+
- [Command Examples](./examples.md)
21+
22+
23+
# Where to start
24+
Because Amino.NET.Interactions is a framework built on top of Amino.NET you first need to initialize your Amino Client
25+
```cs
26+
Amino.Client client = new Amino.Client(); // Note that you should fill in possible parameters if you want
27+
client.login("email", "password"); // You need to be logged into your Amino Account (or the account you plan to use as a bot) make sure to NOT disable your websocket as it will be needed
28+
```
29+
### Creating your interaction Client
30+
The InteractionsClient can be found in the **Amino.Interactions** namespace and needs an **Amino.Client** to be constructed
31+
```cs
32+
InteractionsClient interactionClient = new InteractionsClient(client);
33+
// Our InteractionsClient has a few values we could set, but we will leave it on default for now
34+
```
35+
### Creating your first command module
36+
With Amino.NET.Interactions you can easily create Command Modules, in short: Every class that is **public** and inherits **InteractionBase** is valid to be registered
37+
```cs
38+
public class MyCommandClass : InteractionBase { ... } // This module is valid because it is both public and inherits InteractionBase
39+
```
40+
### Creating your first command
41+
Amino.NET.Interactions has a few Attributes you can use for your commands, they are stored in the **Amino.Interactions.Attributes** namespace, in this case we will use Async Tasks to get our command done, all commands should be stored inside of a **valid module**
42+
```cs
43+
[Command("ping", "Simple Ping Command")]
44+
public async Task PingCommand(Interaction context)
45+
{
46+
await Respond(context, "pong");
47+
}
48+
```
49+
### Registering your modules
50+
In order for your commands to take effect and be usable, you must first register your modules, you have 2 options for it, register them all or register specific ones
51+
```cs
52+
interactionClient.RegisterModule<MyCommandClass>(); // This will register the MyCommandClass as it is a valid module
53+
interactionClient.RegisterModules(Assembly.GetEntryAssemlbly()); // This will register all valid modules of the project, note that it will always need an Assembly object to be constructed, just pass in the EntryAssembly as shown in the example
54+
```
55+
### Handling Interactions
56+
In order for your Interactions to be received, you must first subscribe to an event on the `InteractionsClient`, once that is done, Amino.NET.Interactions will automatically redirect incoming interactions into the corresponding functions.
57+
```cs
58+
interactionClient.InteractionCreated += (ctx) => {
59+
interactionClient.HandleInteraction(ctx); // Note that you could also just build a function instead of catching the event like this
60+
};
61+
```
62+
### Rules and conventions
63+
Amino.NET.Interactions has a few rules to keep in mind, these are:
64+
- In order for a module to be valid it must be **public** and inherit **InteractionBase**
65+
- Every Command function **must** have a parameter of type **Interaction** as its first parameter, this object will be used for our interaction Context, it is located in the **Amino.Interactions.Objects** namespace
66+
- For command parameters you currenly only have 2 options, String and String[], a `string` will contain a single word while `string[]` assume that you want to collect the rest of the message, which is why it is advised to be the last parameter, if you choose to collect all remaining words using a `string[]` parameter, you can find them in `index 0` of the array
67+
- Commands can **not** contain spaces, consider using `-` or `_`

examples.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Amino.NET.Interactions Command Examples
2+
These are some examples of how you could use Amino.NET.Interactions to see what it is capable of.
3+
4+
## Simple Ping command
5+
```cs
6+
[Command("ping", "Simple Ping command")]
7+
public async Task PingCommand(Interaction context)
8+
{
9+
await Respond(context, "Pong");
10+
}
11+
```
12+
## Simple Report Command
13+
```cs
14+
[Command("report", "Simple report command")]
15+
public async Task ReportCommand(Interaction context, string user, string[] reason)
16+
{
17+
Console.WriteLine($"User {context.Message.Author.userName} has reported {user} with reason {reason[0]}");
18+
// Additionally store the report somewhere and or notify staff
19+
await Respond(context, "Thank you for your report, a staff member will shortly look into it")
20+
}
21+
```
22+
23+
## Utility command that only works in a spcific community
24+
```cs
25+
[Command("utility", "Some utility command", 123456)] // 123456 in this case is the communityId
26+
public async Task CommunityCommand(Interaction context)
27+
{
28+
await Respond(context, "Some response");
29+
}
30+
```
31+
## Utility command that does not work in DMs
32+
```cs
33+
[Command("utility", "Some utility command")]
34+
[EnabledInDms(false)]
35+
public async Task NoDmCommand(Interaction context)
36+
{
37+
await Respond(context, "Some response");
38+
}
39+
```
40+
## Utiliy command that can only be accessed by a staff member
41+
```cs
42+
[Command("utility", "Some utility command")]
43+
[PermisionGroup(PermissionGroups.Staff)] // PermissionGroups is located in Amino.Interactions.Attributes.PermissionGroup
44+
public async Task StaffCommand(Interaction context)
45+
{
46+
await Respond(context, "Some response");
47+
}
48+
```
49+
### Additional information
50+
You can mix all these attributes together, the examples only show the bare, to see what other types you can respond with, kindly check out [The Objects Guide](./Objects.md)

0 commit comments

Comments
 (0)