예제 #1
0
# -*- coding: utf-8 -*-
'''
该程序是从demo.py复制过来,稍加改动得到的。
用于得到群聊列表。

'''

from __future__ import unicode_literals

import wechat
import json
import time
import sys
from wechat import WeChatManager, MessageType

wechat_manager = WeChatManager(libs_path='../../../libs')


# 这里测试函数回调
@wechat.CONNECT_CALLBACK(in_class=False)
def on_connect(client_id):
    # print('[on_connect]\nclient_id: {0}'.format(client_id))
    pass


@wechat.RECV_CALLBACK(in_class=False)
def on_recv(client_id, message_type,
            message_data):  # 和LoginTipBot.on_message()效果差不多
    print('[on_recv]\n client_id: {0}\n message_type: {1}\n message:{2}\n'.
          format(client_id, message_type, json.dumps(message_data)))
    pass
예제 #2
0
import datetime, wechat
import json, goldSystem, guessMusic, PRsystem, gift,text_11055
import random
# 签到系统
from wechat import WeChatManager, MessageType

wechat_manager = WeChatManager(libs_path='../../libs')


# def initMemberInfo(client_id, chatRoom):


def signUp(client_id, chatRoom, id):
    nowDate = str(datetime.datetime.now())
    today = str(datetime.date.today())
    submit = '../json/test.json'

    with open(submit, 'r') as r:
        # 全部的数据储存在同一dict中
        # 格式: [date1: [username1, username2]},
        #       {date2: [username1}]
        load_dict = json.load(r)

        # 时间为Key, 签到为value\
        # 如果已经有人签到
        if today in load_dict:
            if id not in load_dict[today]:
                load_dict[today].append(id)  # 添加用户到当前时间key
                wechat_manager.send_chatroom_at_msg(client_id, chatRoom,
                                                    "\u2618\ufe0f{$@}\n\u2618\ufe0f签到成功!\n\u2618\ufe0f签到时间: " + nowDate + "\n\u2618\ufe0f今日排名: " + str(
                                                        load_dict[today].index(id) + 1) + " \n\u2618\ufe0f奖励: 100金币!",