mirror of
https://github.com/Ryubing/RyujinxHelper.git
synced 2025-05-12 18:20:36 +01:00
Fix Starboard's incorrectly showing messages.
This commit is contained in:
parent
7dae016acb
commit
4edb9b9ef3
8 changed files with 81 additions and 39 deletions
7
global.json
Normal file
7
global.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "5.0",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Gommon;
|
||||
using Qmmands;
|
||||
using Volte.Core.Entities;
|
||||
using Volte.Services;
|
||||
|
@ -18,39 +20,57 @@ namespace Volte.Commands.Modules
|
|||
|
||||
[Command("Channel", "Ch")]
|
||||
[Description("Sets the channel to be used by starboard when a message is starred.")]
|
||||
public Task<ActionResult> ChannelAsync(SocketTextChannel channel)
|
||||
public Task<ActionResult> ChannelAsync(
|
||||
[Description("The channel to be used by Starboard.")] SocketTextChannel channel)
|
||||
{
|
||||
Context.Modify(data =>
|
||||
{
|
||||
data.Configuration.Starboard.StarboardChannel = channel.Id;
|
||||
});
|
||||
Context.Modify(data => data.Configuration.Starboard.StarboardChannel = channel.Id);
|
||||
return Ok($"Successfully set the starboard channel to {MentionUtils.MentionChannel(channel.Id)}.");
|
||||
}
|
||||
|
||||
[Command("Amount", "Count")]
|
||||
[Description("Sets the amount of stars required on a message for it to be posted to the Starboard.")]
|
||||
public Task<ActionResult> AmountAsync(int amount)
|
||||
public Task<ActionResult> AmountAsync(
|
||||
[Description("The desired star count threshold before posting it in the starboard channel.")] int amount)
|
||||
{
|
||||
if (amount < 1)
|
||||
{
|
||||
return BadRequest("Amount must be larger than zero.");
|
||||
}
|
||||
|
||||
|
||||
Context.Modify(data => data.Configuration.Starboard.StarsRequiredToPost = amount);
|
||||
|
||||
return Ok($"Set the amount of stars required to be posted as a starboard message to **{amount}**.");
|
||||
}
|
||||
|
||||
[Command("Setup")]
|
||||
[Description("A one-off command that creates a channel for Starboard, with read-only permissions for everyone, and enables the starboard.")]
|
||||
public async Task<ActionResult> SetupAsync(
|
||||
[Description("The name for the Starboard channel that will be created."), Remainder] string channelName = "starboard")
|
||||
{
|
||||
var channel = await Context.Guild.CreateTextChannelAsync(channelName.Replace(" ", "-"), props =>
|
||||
{
|
||||
props.CategoryId = Context.Channel.CategoryId;
|
||||
props.PermissionOverwrites = new List<Overwrite>
|
||||
{
|
||||
new Overwrite(Context.Guild.EveryoneRole.Id, PermissionTarget.Role,
|
||||
new OverwritePermissions(viewChannel: PermValue.Allow, sendMessages: PermValue.Deny))
|
||||
};
|
||||
});
|
||||
|
||||
Context.Modify(data =>
|
||||
{
|
||||
data.Configuration.Starboard.StarsRequiredToPost = amount;
|
||||
data.Configuration.Starboard.Enabled = true;
|
||||
data.Configuration.Starboard.StarboardChannel = channel.Id;
|
||||
});
|
||||
return Ok($"Set the amount of stars required to be posted as a starboard message to **{amount}**.");
|
||||
|
||||
return Ok($"Successfully configured the Starboard functionality, and any starred messages will go to {channel.Mention}.");
|
||||
}
|
||||
|
||||
[Command("Enable")]
|
||||
[Description("Enable or disable the Starboard in this guild.")]
|
||||
public Task<ActionResult> EnableAsync(bool enabled)
|
||||
public Task<ActionResult> EnableAsync(
|
||||
[Description("Whether or not to enable or disable the Starboard.")] bool enabled)
|
||||
{
|
||||
Context.Modify(data =>
|
||||
{
|
||||
data.Configuration.Starboard.Enabled = enabled;
|
||||
});
|
||||
Context.Modify(data => data.Configuration.Starboard.Enabled = enabled);
|
||||
return Ok(
|
||||
enabled ? "Enabled the Starboard in this Guild." : "Disabled the Starboard in this Guild.");
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ using Humanizer;
|
|||
using Volte.Core;
|
||||
using Volte.Core.Entities;
|
||||
using Volte.Core.Helpers;
|
||||
using Volte.Interactive;
|
||||
using Volte.Services;
|
||||
|
||||
namespace Volte.Commands
|
||||
|
@ -23,15 +22,13 @@ namespace Volte.Commands
|
|||
// ReSharper disable once SuggestBaseTypeForParameter
|
||||
private VolteContext(SocketMessage msg, IServiceProvider provider) : base(provider)
|
||||
{
|
||||
if (provider.TryGet<DiscordShardedClient>(out var client))
|
||||
Client = client;
|
||||
Client = provider.Get<DiscordShardedClient>();
|
||||
Guild = msg.Channel.Cast<SocketTextChannel>()?.Guild;
|
||||
Interactive = provider.Get<InteractiveService>();
|
||||
Channel = msg.Channel.Cast<SocketTextChannel>();
|
||||
User = msg.Author.Cast<SocketGuildUser>();
|
||||
Message = msg.Cast<SocketUserMessage>();
|
||||
if (provider.TryGet<DatabaseService>(out var db))
|
||||
GuildData = db.GetData(Guild);
|
||||
GuildData = provider.Get<DatabaseService>().GetData(Guild);
|
||||
Now = DateTime.Now;
|
||||
}
|
||||
|
||||
|
@ -44,7 +41,12 @@ namespace Volte.Commands
|
|||
public SocketUserMessage Message { get; }
|
||||
public GuildData GuildData { get; }
|
||||
public DateTime Now { get; }
|
||||
|
||||
public Embed CreateEmbed(StringBuilder content) => CreateEmbed(content.ToString());
|
||||
|
||||
public Embed CreateEmbed(Action<EmbedBuilder> action)
|
||||
=> CreateEmbedBuilder().Apply(action).Build();
|
||||
|
||||
public Embed CreateEmbed(string content) => CreateEmbedBuilder(content).Build();
|
||||
|
||||
public EmbedBuilder CreateEmbedBuilder(string content = null) => new EmbedBuilder()
|
||||
|
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Gommon;
|
||||
|
||||
namespace Volte.Core.Helpers
|
||||
{
|
||||
|
|
|
@ -150,7 +150,12 @@ namespace Volte.Core.Helpers
|
|||
var mod = provider.Get<ModerationService>();
|
||||
var starboard = provider.Get<StarboardService>();
|
||||
|
||||
client.Log += m => Task.Run(() => Logger.HandleLogEvent(new LogEventArgs(m)));
|
||||
client.Log += async m =>
|
||||
{
|
||||
if (!(m.Message.ContainsIgnoreCase("unknown dispatch") &&
|
||||
m.Message.ContainsIgnoreCase("application_command")))
|
||||
await Task.Run(() => Logger.HandleLogEvent(new LogEventArgs(m)));
|
||||
};
|
||||
|
||||
if (provider.TryGet<GuildService>(out var guild))
|
||||
{
|
||||
|
|
|
@ -13,8 +13,7 @@ namespace Volte.Services
|
|||
{
|
||||
Logger.Debug(LogSource.Service,
|
||||
"Received a message to check for ping threshold violations.");
|
||||
if (args.Message.MentionedEveryone ||
|
||||
args.Message.MentionedUsers.Count > 10)
|
||||
if (args.Message.MentionedEveryone || args.Message.MentionedUsers.Count > 10)
|
||||
{
|
||||
await args.Message.DeleteAsync();
|
||||
Logger.Debug(LogSource.Service,
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using Discord;
|
||||
using Discord.Rest;
|
||||
using Gommon;
|
||||
using Volte.Commands;
|
||||
using Volte.Core.Entities;
|
||||
|
@ -32,17 +33,9 @@ namespace Volte.Services
|
|||
var match = JumpUrlPattern.Match(args.Message.Content);
|
||||
if (!match.Success) return false;
|
||||
|
||||
if (!ulong.TryParse(match.Groups["GuildId"].Value, out var guildId) ||
|
||||
!ulong.TryParse(match.Groups["ChannelId"].Value, out var channelId) ||
|
||||
!ulong.TryParse(match.Groups["MessageId"].Value, out var messageId)) return false;
|
||||
|
||||
var g = await _client.Rest.GetGuildAsync(guildId);
|
||||
if (g is null) return false;
|
||||
var c = await g.GetTextChannelAsync(channelId);
|
||||
if (c is null) return false;
|
||||
|
||||
var m = await c.GetMessageAsync(messageId);
|
||||
var m = await GetMatchMessageAsync(match);
|
||||
if (m is null) return false;
|
||||
|
||||
if (m.Content.IsNullOrWhitespace() && !m.Embeds.IsEmpty()) return false;
|
||||
|
||||
await GenerateQuoteEmbed(m, args.Context).SendToAsync(args.Context.Channel)
|
||||
|
@ -54,6 +47,20 @@ namespace Volte.Services
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<RestMessage> GetMatchMessageAsync(Match match)
|
||||
{
|
||||
if (!ulong.TryParse(match.Groups["GuildId"].Value, out var guildId) ||
|
||||
!ulong.TryParse(match.Groups["ChannelId"].Value, out var channelId) ||
|
||||
!ulong.TryParse(match.Groups["MessageId"].Value, out var messageId)) return null;
|
||||
|
||||
var g = await _client.Rest.GetGuildAsync(guildId);
|
||||
if (g is null) return null;
|
||||
var c = await g.GetTextChannelAsync(channelId);
|
||||
if (c is null) return null;
|
||||
|
||||
return await c.GetMessageAsync(messageId);
|
||||
}
|
||||
|
||||
private Embed GenerateQuoteEmbed(IMessage message, VolteContext ctx)
|
||||
{
|
||||
var e = ctx.CreateEmbedBuilder()
|
||||
|
|
|
@ -270,13 +270,16 @@ namespace Volte.Services
|
|||
.WithAuthor(message.Author)
|
||||
.AddField("Posted", Format.Bold(Format.Url($"#{message.Channel.Name}", message.GetJumpUrl())));
|
||||
|
||||
if (Uri.IsWellFormedUriString(message.Content, UriKind.RelativeOrAbsolute))
|
||||
e.WithImageUrl(message.Content);
|
||||
else if (!message.Attachments.IsEmpty())
|
||||
if (!message.Attachments.IsEmpty() && !message.Content.IsNullOrEmpty())
|
||||
e.WithDescription(message.Content).WithImageUrl(message.Attachments.First().Url);
|
||||
if (message.Attachments.IsEmpty() && !message.Content.IsNullOrEmpty())
|
||||
e.WithDescription(message.Content);
|
||||
if (!message.Attachments.IsEmpty() && message.Content.IsNullOrEmpty())
|
||||
e.WithImageUrl(message.Attachments.First().Url);
|
||||
|
||||
if (message.Attachments.IsEmpty())
|
||||
e.WithDescription(message.Content);
|
||||
if (message.Attachments.Count > 1)
|
||||
e.WithFooter($"This message has {message.Attachments.Count - 1} more attachments. See original message.");
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue