mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Where is Xur?
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AssemblyName>Kruzya.TelegramBot.D2_WhereIsXur</AssemblyName>
|
||||
<RootNamespace>Kruzya.TelegramBot.Destiny2.WhereIsXur</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.0" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.21" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider
|
||||
{
|
||||
public interface IXurPlaceProvider
|
||||
{
|
||||
public Task<string> GetPlaceAsync();
|
||||
public string GetPlace();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using Fizzler.Systems.HtmlAgilityPack;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider
|
||||
{
|
||||
public class XurWiki : IXurPlaceProvider
|
||||
{
|
||||
public async Task<string> GetPlaceAsync()
|
||||
{
|
||||
var web = new HtmlWeb();
|
||||
var document = await web.LoadFromWebAsync("https://xur.wiki");
|
||||
|
||||
var place = document.DocumentNode.QuerySelector(".location_name");
|
||||
if (place != null)
|
||||
{
|
||||
return place.InnerText.Trim();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public string GetPlace()
|
||||
{
|
||||
return GetPlaceAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework;
|
||||
using BotFramework.Attributes;
|
||||
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
||||
{
|
||||
public class RequestHandler : BotEventHandler
|
||||
{
|
||||
protected readonly IXurPlaceProvider _placeProvider;
|
||||
|
||||
public RequestHandler(IXurPlaceProvider xurPlaceProvider)
|
||||
{
|
||||
_placeProvider = xurPlaceProvider;
|
||||
}
|
||||
|
||||
[Command("d2_xur")]
|
||||
public async Task WhereIsXur()
|
||||
{
|
||||
var place = await _placeProvider.GetPlaceAsync();
|
||||
if (string.IsNullOrWhiteSpace(place))
|
||||
{
|
||||
await Response("unknown");
|
||||
return;
|
||||
}
|
||||
|
||||
await Response(place);
|
||||
}
|
||||
|
||||
protected async Task Response(string place)
|
||||
{
|
||||
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", ParseMode.Html);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
||||
{
|
||||
public class WhereIsXur : Module
|
||||
{
|
||||
public WhereIsXur(Core.Core core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IXurPlaceProvider, XurWiki>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user