Adding multiple projects & API
This commit is contained in:
22
Kasbot.APP/Internal/Services/StatusService.cs
Normal file
22
Kasbot.APP/Internal/Services/StatusService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Grpc.Core;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Status;
|
||||
|
||||
namespace Kasbot.App.Internal.Services
|
||||
{
|
||||
public class StatusService : StatusRequester.StatusRequesterBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public StatusService(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<StatusService>();
|
||||
}
|
||||
|
||||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
|
||||
{
|
||||
_logger.LogInformation($"Sending hello to {request.Name}");
|
||||
return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,8 +15,19 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.12.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.59.0" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.59.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="YoutubeExplode" Version="6.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="../Proto/status.proto" GrpcServices="Kasbot.App" Link="Protos\status.proto" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -1,13 +1,16 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Kasbot.App.Internal.Services;
|
||||
using Kasbot.Services;
|
||||
using Kasbot.Services.Internal;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kasbot
|
||||
{
|
||||
class Program
|
||||
public class Program
|
||||
{
|
||||
private static string TOKEN = Environment.GetEnvironmentVariable("TOKEN");
|
||||
private static int SHARDS = int.Parse(Environment.GetEnvironmentVariable("SHARDS") ?? "0");
|
||||
@@ -24,17 +27,28 @@ namespace Kasbot
|
||||
SHARDS = 1;
|
||||
}
|
||||
|
||||
Task.Factory.StartNew(() => new Program().RunGrpc(args));
|
||||
|
||||
new Program()
|
||||
.MainAsync()
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
private void RunGrpc(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddGrpc();
|
||||
|
||||
var app = builder.Build();
|
||||
app.MapGrpcService<StatusService>();
|
||||
app.Run(url: "https://localhost:7042");
|
||||
}
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
using (var services = ConfigureServices())
|
||||
{
|
||||
|
||||
var client = services.GetRequiredService<DiscordShardedClient>();
|
||||
|
||||
client.Log += LogAsync;
|
||||
|
Reference in New Issue
Block a user