-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get the MessageChain for the Reply through the BotContext.
- Loading branch information
Showing
8 changed files
with
79 additions
and
59 deletions.
There are no files selected for viewing
Submodule Lagrange.Core
updated
11 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.Core.Message; | ||
|
||
namespace Lagrange.Kritor.Utilities; | ||
|
||
public static class BotContextUtility { | ||
public static async Task<MessageChain> GetMessageByMessageIdAsync(this BotContext bot, string id, CancellationToken token) { | ||
uint sequence = MessageIdUtility.GetSequence(id); | ||
uint uin = MessageIdUtility.GetUin(id); | ||
|
||
List<MessageChain>? chains; | ||
if (MessageIdUtility.IsGroup(id)) { | ||
chains = await bot.GetGroupMessage(uin, sequence, sequence); | ||
} else if (MessageIdUtility.IsGroup(id)) { | ||
chains = await bot.GetC2cMessage(uin, sequence, sequence); | ||
} else throw new NotSupportedException($"Not supported message id({id})"); | ||
|
||
if (chains == null || chains.Count != 1) { | ||
throw new Exception($"Get message chain by message id({id}) failed"); | ||
} | ||
|
||
return chains[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters