mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
.send commmand reworked, It should be much better and more reliable now.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#nullable disable
|
||||
using Discord.Rest;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
using NadekoBot.Db.Models;
|
||||
using Nadeko.Common.Medusa;
|
||||
@@ -62,9 +63,9 @@ public partial class Administration
|
||||
|
||||
await message.ModifyAsync(x =>
|
||||
x.Embed = _sender.CreateEmbed()
|
||||
.WithDescription(GetText(strs.cache_users_done(added, updated)))
|
||||
.WithOkColor()
|
||||
.Build()
|
||||
.WithDescription(GetText(strs.cache_users_done(added, updated)))
|
||||
.WithOkColor()
|
||||
.Build()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ public partial class Administration
|
||||
&& ctx.Message is SocketUserMessage msg)
|
||||
{
|
||||
var fakeMessage = new DoAsUserMessage(msg, user, message);
|
||||
|
||||
|
||||
|
||||
await _cmdHandler.TryRunCommand(sg, ch, fakeMessage);
|
||||
}
|
||||
@@ -115,13 +116,13 @@ public partial class Administration
|
||||
|
||||
await Response()
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.scadd))
|
||||
.AddField(GetText(strs.server),
|
||||
cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}",
|
||||
true)
|
||||
.AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true)
|
||||
.AddField(GetText(strs.command_text), cmdText))
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.scadd))
|
||||
.AddField(GetText(strs.server),
|
||||
cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}",
|
||||
true)
|
||||
.AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true)
|
||||
.AddField(GetText(strs.command_text), cmdText))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
@@ -546,51 +547,41 @@ public partial class Administration
|
||||
await Response().Confirm(strs.set_stream).SendAsync();
|
||||
}
|
||||
|
||||
public enum SendWhere
|
||||
{
|
||||
User = 0,
|
||||
U = 0,
|
||||
Usr = 0,
|
||||
|
||||
Channel = 1,
|
||||
Ch = 1,
|
||||
Chan = 1,
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task Send(string where, [Leftover] SmartText text = null)
|
||||
public async Task Send(SendWhere to, ulong id, [Leftover] SmartText text)
|
||||
{
|
||||
var ids = where.Split('|');
|
||||
if (ids.Length != 2)
|
||||
return;
|
||||
|
||||
var sid = ulong.Parse(ids[0]);
|
||||
var server = _client.Guilds.FirstOrDefault(s => s.Id == sid);
|
||||
|
||||
if (server is null)
|
||||
return;
|
||||
|
||||
// var repSvc = new ReplacementBuilder().WithDefault(Context).Build();
|
||||
var repCtx = new ReplacementContext(Context);
|
||||
|
||||
if (ids[1].ToUpperInvariant().StartsWith("C:", StringComparison.InvariantCulture))
|
||||
var ch = to switch
|
||||
{
|
||||
var cid = ulong.Parse(ids[1][2..]);
|
||||
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
||||
if (ch is null)
|
||||
return;
|
||||
SendWhere.User => await ((await _client.Rest.GetUserAsync(id))?.CreateDMChannelAsync()
|
||||
?? Task.FromResult<RestDMChannel>(null)),
|
||||
SendWhere.Channel => await _client.Rest.GetChannelAsync(id) as IMessageChannel,
|
||||
_ => null
|
||||
};
|
||||
|
||||
text = await repSvc.ReplaceAsync(text, repCtx);
|
||||
await Response().Channel(ch).Text(text).SendAsync();
|
||||
}
|
||||
else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
|
||||
{
|
||||
var uid = ulong.Parse(ids[1][2..]);
|
||||
var user = server.Users.FirstOrDefault(u => u.Id == uid);
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
var ch = await user.CreateDMChannelAsync();
|
||||
text = await repSvc.ReplaceAsync(text, repCtx);
|
||||
await Response().Channel(ch).Text(text).SendAsync();
|
||||
}
|
||||
else
|
||||
if (ch is null)
|
||||
{
|
||||
await Response().Error(strs.invalid_format).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await Response().Confirm(strs.message_sent).SendAsync();
|
||||
|
||||
var repCtx = new ReplacementContext(ctx);
|
||||
text = await repSvc.ReplaceAsync(text, repCtx);
|
||||
await Response().Channel(ch).Text(text).SendAsync();
|
||||
|
||||
await ctx.OkAsync();;
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
@@ -466,7 +466,13 @@ public sealed class SourcedPaginatedResponseBuilder<T> : PaginatedResponseBuilde
|
||||
|
||||
public SourcedPaginatedResponseBuilder<T> Interaction(Func<int, Task<SimpleInteractionBase>> func)
|
||||
{
|
||||
InteractionFunc = async (i) => await func(i);
|
||||
InteractionFunc = func; //async (i) => await func(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourcedPaginatedResponseBuilder<T> Interaction(SimpleInteractionBase inter)
|
||||
{
|
||||
InteractionFunc = _ => Task.FromResult(inter);
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -413,10 +413,10 @@ setgame:
|
||||
- "Watching anime."
|
||||
- "Listening music."
|
||||
send:
|
||||
desc: "Sends a message to someone on a different server through the bot. Separate server and channel/user ids with `|` and prefix the channel id with `c:` and the user id with `u:`."
|
||||
desc: "Sends a message to a channel or user. Channel or user can be "
|
||||
args:
|
||||
- "serverid|c:channelid message"
|
||||
- "serverid|u:userid message"
|
||||
- "channel 123123123132312 Stop spamming commands plz"
|
||||
- "user 1231231232132 I can see in the console what you're doing."
|
||||
savechat:
|
||||
desc: "Saves a number of messages to a text file and sends it to you."
|
||||
args:
|
||||
|
Reference in New Issue
Block a user