Ejemplo n.º 1
0
class qqbot(Bot):
    """CoolQ Bot."""
    def __init__(self, cqroot, group_id):
        self._cqbot = CQHttp(api_root=cqroot)
        self.group_id = group_id

    def sendmessage(self, message):
        self._cqbot.send_group_msg(group_id=self.group_id, message=message)
Ejemplo n.º 2
0
def job():
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    bot = CQHttp(api_root=config.api_root,
                 access_token=config.access_token,
                 secret=config.secret)

    for i in config.QQ_Group:
        twis = rss.twigen(i[0], time_in_minutes, i[2])
        for k in twis:
            print(k)
            for j in i[1]:
                bot.send_group_msg(group_id=j, message=k)
                time.sleep(5)

    for i in config.QQ_Private:
        twis = rss.twigen(i[0], time_in_minutes, i[2])
        for k in twis:
            print(k)
            for j in i[1]:
                bot.send_private_msg(user_id=j, message=k)
                time.sleep(5)
Ejemplo n.º 3
0
class CQclient(object):
    '''
    酷Q机器人
    : func single_msg: 发送私聊信息
    : func group_msg: 发送群聊信息
    : param single_id: 私聊QQ号 list
    : param group_id: 群聊QQ号 list
    '''
    def __init__(self):
        self.bot = CQHttp(api_root='http://127.0.0.1:5700/')
        self.single_id = [526189921]
        self.group_id = []

    def single_msg(self, msg):
        '''
        发送私聊信息
        : param msg: 需要发送的信息 string
        : return: 发送结果 list
        '''
        try:
            return [
                self.bot.send_private_msg(message=msg,
                                          user_id=_id,
                                          auto_escape=False)
                for _id in self.single_id
            ]
        except:
            print(msg)

    def group_msg(self, msg):
        '''
        发送群聊信息
        : param msg: 需要发送的信息 string
        : return: 发送结果 list
        '''
        try:
            return [
                self.bot.send_group_msg(message=msg,
                                        group_id=_id,
                                        auto_escape=False)
                for _id in self.group_id
            ]
        except:
            print(msg)
Ejemplo n.º 4
0
def handle_massage(context):
    new_message = context['message']
    bot.send_msg(733508010, "奇怪,应该能发消息呀")

    if context['group_id'] == 733508010:
        conn = sqlite3.connect("GroupRecord.db")
        cursor = conn.cursor()
        cursor.execute("SELECT times FROM messages WHERE message=?",
                       (new_message, ))
        values = cursor.fetchall()
        if len(values) == 0:
            cursor.execute(
                "INSERT INTO messages (message, times) values (?, 1)",
                (new_message, ))
        else:
            cursor.execute("UPDATE messages SET times=times+1 WHERE message=?",
                           (new_message, ))
        cursor.close()
        conn.commit()
        conn.close()

    return {"reply": None, 'at_sender': False}


bot.run(host='127.0.0.1', port=8080, debug=True)
bot.send_group_msg(733508010, "奇怪,应该能发消息呀")

sched = BlockingScheduler()
sched.add_job(report, 'cron', day_of_week='0-6', hour='22')
sched.start()