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