mirror of
https://github.com/yawaflua/PL_JusticeBot.git
synced 2025-12-09 20:09:31 +02:00
add ephemeral messages and fix some bugs
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using DiscordApp.Database;
|
using DiscordApp.Database;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace DiscordApp.Controllers
|
namespace DiscordApp.Controllers
|
||||||
@@ -10,8 +11,8 @@ namespace DiscordApp.Controllers
|
|||||||
public class redirects : ControllerBase
|
public class redirects : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
[HttpGet("/redirects/{uri}")]
|
[HttpGet("/redirects/{uri}&channelid={channelid}")]
|
||||||
public IActionResult Get(string uri, [FromBody] string? bodyContent)
|
public async Task<IActionResult> Get(string uri, [FromBody] string? bodyContent, ulong channelid)
|
||||||
{
|
{
|
||||||
var data = Startup.appDbContext.Redirects.First(k => k.Id == uri);
|
var data = Startup.appDbContext.Redirects.First(k => k.Id == uri);
|
||||||
if (data.RedirectType == Types.RedirectType.None)
|
if (data.RedirectType == Types.RedirectType.None)
|
||||||
@@ -22,18 +23,16 @@ namespace DiscordApp.Controllers
|
|||||||
return Redirect(data.url);
|
return Redirect(data.url);
|
||||||
}else if (data.RedirectType == Types.RedirectType.Redirected)
|
}else if (data.RedirectType == Types.RedirectType.Redirected)
|
||||||
{
|
{
|
||||||
JsonNode jsonBodyContent = JsonNode.Parse(bodyContent);
|
var guild = Startup.discordSocketClient.GetGuild(1107742957458685985);
|
||||||
string[] paymentData = jsonBodyContent["data"].ToString().Split(";");
|
var channel = guild.GetChannel(channelid) as ITextChannel;
|
||||||
var channelId = paymentData[1].Split(":")[1];
|
var message = channel.GetMessagesAsync().LastOrDefaultAsync().Result.FirstOrDefault() as IUserMessage;
|
||||||
var channel = Startup.discordSocketClient.GetChannel(ulong.Parse(channelId)) as ITextChannel;
|
await message.ModifyAsync(func =>
|
||||||
var message = channel.GetMessagesAsync().LastAsync().Result.Last() as IUserMessage;
|
|
||||||
message.ModifyAsync(func =>
|
|
||||||
{
|
{
|
||||||
func.Content = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!";
|
func.Content = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!";
|
||||||
func.Components = new ComponentBuilder()
|
func.Components = new ComponentBuilder()
|
||||||
.WithButton("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "addBaseOnMapModalSender")
|
.WithButton("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "addBaseOnMapModalSender")
|
||||||
.Build();
|
.Build();
|
||||||
}).RunSynchronously();
|
});
|
||||||
|
|
||||||
return Redirect(message.GetJumpUrl());
|
return Redirect(message.GetJumpUrl());
|
||||||
}
|
}
|
||||||
@@ -42,23 +41,17 @@ namespace DiscordApp.Controllers
|
|||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpPost("/redirects/{uri}")]
|
[HttpGet("/redirects/{uri}")]
|
||||||
public IActionResult Post(string uri, [FromBody] string bodyContent)
|
public IActionResult Post(string uri)
|
||||||
{
|
{
|
||||||
JsonNode jsonBodyContent = JsonNode.Parse(bodyContent);
|
var data = Startup.appDbContext.Redirects.First(k => k.Id == uri);
|
||||||
string[] paymentData = jsonBodyContent["data"].ToString().Split(";");
|
|
||||||
var channelId = paymentData[1].Split(":")[1];
|
data.RedirectType = Types.RedirectType.Redirected;
|
||||||
var channel = Startup.discordSocketClient.GetChannel(ulong.Parse(channelId)) as ITextChannel;
|
Startup.appDbContext.Redirects.Update(data);
|
||||||
var message = channel.GetMessagesAsync().LastAsync().Result.Last() as IUserMessage;
|
Startup.appDbContext.SaveChanges();
|
||||||
message.ModifyAsync(func =>
|
return Redirect(data.url);
|
||||||
{
|
|
||||||
func.Content = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!";
|
|
||||||
func.Components = new ComponentBuilder()
|
|
||||||
.WithButton("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "addBaseOnMapModalSender")
|
|
||||||
.Build();
|
|
||||||
}).RunSynchronously();
|
|
||||||
|
|
||||||
return Ok(message.GetJumpUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace DiscordApp
|
|||||||
await client.LoginAsync(TokenType.Bot, "MTE2NjA3OTk3NjQ0NjEwMzYwMg.GAKOIo.4af972Wh11G0EF4O5tNYb7l-vt5OwMc4HPRnjE");
|
await client.LoginAsync(TokenType.Bot, "MTE2NjA3OTk3NjQ0NjEwMzYwMg.GAKOIo.4af972Wh11G0EF4O5tNYb7l-vt5OwMc4HPRnjE");
|
||||||
await client.StartAsync();
|
await client.StartAsync();
|
||||||
await interactionHandler.InitializeAsync();
|
await interactionHandler.InitializeAsync();
|
||||||
|
Startup.discordSocketClient = client;
|
||||||
await Task.Delay(Timeout.Infinite);
|
await Task.Delay(Timeout.Infinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,20 +11,24 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
[ComponentInteraction("addBaseOnMap")]
|
[ComponentInteraction("addBaseOnMap")]
|
||||||
public async Task addBaseInteraction()
|
public async Task addBaseInteraction()
|
||||||
{
|
{
|
||||||
var redirectUri = Guid.NewGuid().ToString();
|
|
||||||
await DeferAsync(true);
|
await DeferAsync(true);
|
||||||
|
var thread = await ((ITextChannel)Context.Channel).CreateThreadAsync($"{Context.User.GlobalName}-addCityOnMap", ThreadType.PrivateThread) as IThreadChannel;
|
||||||
|
await thread.AddUserAsync(((IGuildUser)Context.User));
|
||||||
|
await FollowupAsync(thread.Mention, ephemeral:true);
|
||||||
|
var redirectUri = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
var paymentData = new spworlds.Types.PaymentData()
|
var paymentData = new spworlds.Types.PaymentData()
|
||||||
{
|
{
|
||||||
Amount = 16,
|
Amount = 16,
|
||||||
Data = $"user:{Context.User.Id};channel:{Context.Channel.Id};",
|
Data = $"user:{Context.User.Id};channel:{thread.Id};",
|
||||||
RedirectUrl = $"https://discord.yawaflua.ru/redirects/{redirectUri}",
|
RedirectUrl = $"https://discord.yawaflua.ru/redirects/{redirectUri}&channelid={thread.Id}",
|
||||||
WebHookUrl = $"https://discord.yawaflua.ru/redirects/{redirectUri}"
|
WebHookUrl = $"https://discord.yawaflua.ru/redirects/{redirectUri}"
|
||||||
};
|
};
|
||||||
var uri = await Startup.sp.InitPayment(paymentData);
|
var uri = await Startup.sp.InitPayment(paymentData);
|
||||||
var redirectTable = new Redirects() { Id = redirectUri , url = uri};
|
var redirectTable = new Redirects() { Id = redirectUri , url = uri};
|
||||||
Startup.appDbContext.Redirects.Add(redirectTable);
|
Startup.appDbContext.Redirects.Add(redirectTable);
|
||||||
Startup.appDbContext.SaveChanges();
|
Startup.appDbContext.SaveChanges();
|
||||||
await FollowupAsync("Нажмите на кнопку ниже для оплаты", components: new ComponentBuilder().WithButton("Оплатить", url: $"https://discord.yawaflua.ru/redirects/{redirectUri}", style: ButtonStyle.Link).Build(), ephemeral: true);
|
await thread.SendMessageAsync("Нажмите на кнопку ниже для оплаты", components: new ComponentBuilder().WithButton("Оплатить", url: $"https://discord.yawaflua.ru/redirects/{redirectUri}", style: ButtonStyle.Link).Build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +71,8 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
var channel = Context.Guild.GetTextChannel(1174722397820174439);
|
var channel = Context.Guild.GetTextChannel(1174722397820174439);
|
||||||
await channel.SendMessageAsync("@ #here", embed: embed, components: components);
|
await channel.SendMessageAsync("@ #here", embed: embed, components: components);
|
||||||
await FollowupAsync("Заявка подана и передана ответственным лицам. Ожидайте!", ephemeral: true);
|
await FollowupAsync("Заявка подана и передана ответственным лицам. Ожидайте!", ephemeral: true);
|
||||||
|
var threadChannel = Context.Channel as IThreadChannel;
|
||||||
|
await threadChannel.ModifyAsync(k => k.Archived = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ComponentInteraction("accessNewBase")]
|
[ComponentInteraction("accessNewBase")]
|
||||||
@@ -115,15 +121,36 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await startup.addSityOnMap(city);
|
await startup.addSityOnMap(city);
|
||||||
await FollowupAsync("Все готово!");
|
await FollowupAsync("Все готово!", ephemeral: true);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await FollowupAsync("Какая-то ошибка, чекни логи");
|
await FollowupAsync("Какая-то ошибка, чекни логи", ephemeral: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
[ComponentInteraction("declineNewBase")]
|
||||||
|
public async Task declineBaseOnMap()
|
||||||
|
{
|
||||||
|
await DeferAsync(true);
|
||||||
|
|
||||||
|
var components = new ComponentBuilder()
|
||||||
|
.WithButton(customId: "accessNewBase", label: "✅", disabled: true)
|
||||||
|
.WithButton(customId: "declineNewBase", label: "❌", disabled: true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await ModifyOriginalResponseAsync(func => { func.Components = components; func.Content = $"Заявку отозвал {Context.User.Mention}"; });
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await FollowupAsync("Все готово!", ephemeral:true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
await FollowupAsync("Какая-то ошибка, чекни логи", ephemeral:true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ namespace DiscordApp
|
|||||||
|
|
||||||
serviceProvider = services.BuildServiceProvider();
|
serviceProvider = services.BuildServiceProvider();
|
||||||
appDbContext = serviceProvider.GetRequiredService<AppDbContext>();
|
appDbContext = serviceProvider.GetRequiredService<AppDbContext>();
|
||||||
discordSocketClient = serviceProvider.GetRequiredService<DiscordSocketClient>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
|||||||
Reference in New Issue
Block a user