mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-03 16:24:27 -05:00
.send commmand reworked, It should be much better and more reliable now.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
using Discord.Rest;
|
||||||
using NadekoBot.Modules.Administration.Services;
|
using NadekoBot.Modules.Administration.Services;
|
||||||
using NadekoBot.Db.Models;
|
using NadekoBot.Db.Models;
|
||||||
using Nadeko.Common.Medusa;
|
using Nadeko.Common.Medusa;
|
||||||
@@ -546,51 +547,41 @@ public partial class Administration
|
|||||||
await Response().Confirm(strs.set_stream).SendAsync();
|
await Response().Confirm(strs.set_stream).SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum SendWhere
|
||||||
|
{
|
||||||
|
User = 0,
|
||||||
|
U = 0,
|
||||||
|
Usr = 0,
|
||||||
|
|
||||||
|
Channel = 1,
|
||||||
|
Ch = 1,
|
||||||
|
Chan = 1,
|
||||||
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[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('|');
|
var ch = to switch
|
||||||
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 cid = ulong.Parse(ids[1][2..]);
|
SendWhere.User => await ((await _client.Rest.GetUserAsync(id))?.CreateDMChannelAsync()
|
||||||
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
?? Task.FromResult<RestDMChannel>(null)),
|
||||||
|
SendWhere.Channel => await _client.Rest.GetChannelAsync(id) as IMessageChannel,
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
|
||||||
if (ch is null)
|
if (ch is null)
|
||||||
return;
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
await Response().Error(strs.invalid_format).SendAsync();
|
await Response().Error(strs.invalid_format).SendAsync();
|
||||||
return;
|
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]
|
[Cmd]
|
||||||
|
|||||||
@@ -466,7 +466,13 @@ public sealed class SourcedPaginatedResponseBuilder<T> : PaginatedResponseBuilde
|
|||||||
|
|
||||||
public SourcedPaginatedResponseBuilder<T> Interaction(Func<int, Task<SimpleInteractionBase>> func)
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,10 +413,10 @@ setgame:
|
|||||||
- "Watching anime."
|
- "Watching anime."
|
||||||
- "Listening music."
|
- "Listening music."
|
||||||
send:
|
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:
|
args:
|
||||||
- "serverid|c:channelid message"
|
- "channel 123123123132312 Stop spamming commands plz"
|
||||||
- "serverid|u:userid message"
|
- "user 1231231232132 I can see in the console what you're doing."
|
||||||
savechat:
|
savechat:
|
||||||
desc: "Saves a number of messages to a text file and sends it to you."
|
desc: "Saves a number of messages to a text file and sends it to you."
|
||||||
args:
|
args:
|
||||||
|
|||||||
Reference in New Issue
Block a user