-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from AmiyaBot/dev
Dev
- Loading branch information
Showing
10 changed files
with
153 additions
and
108 deletions.
There are no files selected for viewing
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,53 @@ | ||
""" | ||
https://bot.q.qq.com/wiki/develop/api-v2/dev-prepare/interface-framework/event-emit.html#websocket-%E6%96%B9%E5%BC%8F | ||
""" | ||
import enum | ||
|
||
|
||
class IntentsClass(enum.Enum): | ||
@classmethod | ||
def calc(cls): | ||
intent = 0 | ||
for item in cls: | ||
intent |= item.value | ||
return intent | ||
|
||
|
||
class CommonIntents(IntentsClass): | ||
GUILDS = 1 << 0 | ||
GUILD_MEMBERS = 1 << 1 | ||
GUILD_MESSAGE_REACTIONS = 1 << 10 | ||
DIRECT_MESSAGE = 1 << 12 | ||
INTERACTION = 1 << 26 | ||
MESSAGE_AUDIT = 1 << 27 | ||
AUDIO_ACTION = 1 << 29 | ||
|
||
|
||
class PublicIntents(IntentsClass): | ||
PUBLIC_GUILD_MESSAGES = 1 << 30 | ||
|
||
|
||
class PrivateIntents(IntentsClass): | ||
GUILD_MESSAGES = 1 << 9 | ||
FORUMS_EVENT = 1 << 28 | ||
|
||
|
||
class GroupIntents(IntentsClass): | ||
GROUP_AND_C2C_EVENT = 1 << 25 | ||
|
||
|
||
def get_intents(private: bool, name: str) -> int: | ||
if name == 'QQGroup': | ||
return GroupIntents.calc() | ||
|
||
res = CommonIntents.calc() | ||
|
||
if private: | ||
res |= PrivateIntents.calc() | ||
else: | ||
res |= PublicIntents.calc() | ||
|
||
if name == 'QQGlobal': | ||
res |= GroupIntents.calc() | ||
|
||
return res |
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,27 @@ | ||
from amiyabot.builtin.messageChain import Chain, ChainBuilder | ||
from amiyabot.adapters.tencent.qqGuild import QQGuildBotInstance | ||
from amiyabot.adapters.tencent.qqGroup import QQGroupBotInstance | ||
|
||
from .package import package_qq_global_message | ||
|
||
|
||
class QQGlobalBotInstance(QQGroupBotInstance): | ||
def __init__(self, appid: str, token: str, client_secret: str, default_chain_builder: ChainBuilder): | ||
super().__init__(appid, token, client_secret, default_chain_builder) | ||
|
||
self.guild = QQGuildBotInstance(appid, token) | ||
|
||
def __str__(self): | ||
return 'QQGlobal' | ||
|
||
@property | ||
def package_method(self): | ||
return package_qq_global_message | ||
|
||
async def send_chain_message(self, chain: Chain, is_sync: bool = False): | ||
if not (chain.data.channel_openid or chain.data.user_openid): | ||
return await self.guild.send_chain_message(chain, is_sync) | ||
return await super().send_chain_message(chain, is_sync) | ||
|
||
|
||
qq_global = QQGlobalBotInstance.build_adapter |
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,20 @@ | ||
from amiyabot.adapters import BotAdapterProtocol | ||
from amiyabot.adapters.tencent.qqGroup.package import package_qq_group_message | ||
from amiyabot.adapters.tencent.qqGuild.package import package_qq_guild_message | ||
|
||
|
||
async def package_qq_global_message( | ||
instance: BotAdapterProtocol, | ||
event: str, | ||
message: dict, | ||
is_reference: bool = False, | ||
): | ||
group_message_created = [ | ||
'C2C_MESSAGE_CREATE', | ||
'GROUP_AT_MESSAGE_CREATE', | ||
] | ||
|
||
if event in group_message_created: | ||
return await package_qq_group_message(instance, event, message, is_reference) | ||
|
||
return await package_qq_guild_message(instance, event, message, is_reference) |
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 was deleted.
Oops, something went wrong.
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