1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-09 23:15:41 +00:00

[ci skip] Add VpSharp.Commands example to samples

This commit is contained in:
Oliver Booth 2022-12-06 19:50:08 +00:00
parent 4c31eb58a9
commit 434dc204d9
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
6 changed files with 46 additions and 4 deletions

View File

@ -1,4 +1,5 @@
using VpSharp.EventData;
using VpSharp.Commands;
using VpSharp.EventData;
namespace VpSharp.CSharp_Sample;
@ -17,6 +18,8 @@ internal static class Program
};
s_client = new VirtualParadiseClient(configuration);
var commands = s_client.UseCommands(new CommandsExtensionConfiguration {Prefixes = {"/"}});
commands.RegisterCommands<SayCommand>();
s_client.AvatarJoined += ClientOnAvatarJoined;

View File

@ -0,0 +1,13 @@
using VpSharp.Commands;
using VpSharp.Commands.Attributes;
namespace VpSharp.CSharp_Sample;
public class SayCommand : CommandModule
{
[Command("say")]
public async Task SayAsync(CommandContext context, [Remainder] string message)
{
await context.RespondAsync(message);
}
}

View File

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\VpSharp.Commands\VpSharp.Commands.csproj" />
<ProjectReference Include="..\..\VpSharp\VpSharp.csproj" />
</ItemGroup>

View File

@ -1,3 +1,4 @@
Imports VpSharp.Commands
Imports VpSharp.EventData
Module Program
@ -6,7 +7,7 @@ Module Program
Public Sub Main(args As String())
MainAsync().GetAwaiter().GetResult()
End Sub
Private Async Function MainAsync() As Task
Dim configuration = new VirtualParadiseConfiguration _
With {
@ -17,16 +18,27 @@ Module Program
}
_client = New VirtualParadiseClient(configuration)
Dim commands = _client.UseCommands(New CommandsExtensionConfiguration With { .Prefixes = {"/"} })
commands.RegisterCommands(GetType(SayCommand))
Await _client.ConnectAsync()
Await _client.LoginAsync()
Await _client.EnterAsync("WORLD_NAME")
Await _client.CurrentAvatar.TeleportAsync(Vector3d.Zero)
Await Task.Delay(-1)
Await Task.Delay(- 1)
End Function
Private Async Sub ClientOnAvatarJoined(sender As Object, args As AvatarJoinedEventArgs) Handles _client.AvatarJoined
Await _client.SendMessageAsync("Hello, " & args.Avatar.Name)
End Sub
Private Async Sub OnChatMessage(sender As Object, args As MessageReceivedEventArgs) Handles _client.MessageReceived
Dim message As String = args.Message.Content
If message.StartsWith("/say ") Then
Await _client.SendMessageAsync(message.Substring(5))
End If
End Sub
End Module

View File

@ -0,0 +1,12 @@
Imports VpSharp.Commands
Imports VpSharp.Commands.Attributes
Public Class SayCommand
Inherits CommandModule
<Command("say")>
Public Async Function SayAsync(context as CommandContext, <Remainder> message As String) As Task
Await context.RespondAsync(message)
End Function
End Class

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\VpSharp.Commands\VpSharp.Commands.csproj" />
<ProjectReference Include="..\..\VpSharp\VpSharp.csproj" />
</ItemGroup>