|
|
@@ -1,14 +1,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
from asyncio import CancelledError |
|
|
|
import queue |
|
|
|
from concurrent.futures import Future, ThreadPoolExecutor |
|
|
|
import os |
|
|
|
import re |
|
|
|
import threading |
|
|
|
import time |
|
|
|
from channel.chat_message import ChatMessage |
|
|
|
from common.expired_dict import ExpiredDict |
|
|
|
from common.dequeue import Dequeue |
|
|
|
from channel.channel import Channel |
|
|
|
from bridge.reply import * |
|
|
|
from bridge.context import * |
|
|
@@ -245,8 +243,11 @@ class ChatChannel(Channel): |
|
|
|
session_id = context['session_id'] |
|
|
|
with self.lock: |
|
|
|
if session_id not in self.sessions: |
|
|
|
self.sessions[session_id] = (queue.Queue(), threading.BoundedSemaphore(conf().get("concurrency_in_session", 1))) |
|
|
|
self.sessions[session_id][0].put(context) |
|
|
|
self.sessions[session_id] = (Dequeue(), threading.BoundedSemaphore(conf().get("concurrency_in_session", 1))) |
|
|
|
if context.type == ContextType.TEXT and context.content.startswith("#"): |
|
|
|
self.sessions[session_id][0].putleft(context) # 优先处理命令 |
|
|
|
else: |
|
|
|
self.sessions[session_id][0].put(context) |
|
|
|
|
|
|
|
# 消费者函数,单独线程,用于从消息队列中取出消息并处理 |
|
|
|
def consume(self): |
|
|
@@ -277,7 +278,7 @@ class ChatChannel(Channel): |
|
|
|
if session_id in self.sessions: |
|
|
|
for future in self.futures[session_id]: |
|
|
|
future.cancel() |
|
|
|
self.sessions[session_id][0]=queue.Queue() |
|
|
|
self.sessions[session_id][0]=Dequeue() |
|
|
|
|
|
|
|
|
|
|
|
def check_prefix(content, prefix_list): |
|
|
|