parent
86d2318fed
commit
2e4c61a5c8
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
"""
|
||||
@version: ??
|
||||
@author: liangliangyy
|
||||
@license: MIT Licence
|
||||
@contact: liangliangyy@gmail.com
|
||||
@site: https://www.lylinux.org/
|
||||
@software: PyCharm
|
||||
@file: MemcacheStorage.py
|
||||
@time: 2017/8/27 上午2:42
|
||||
"""
|
||||
from werobot.session import SessionStorage
|
||||
from werobot.utils import json_loads, json_dumps
|
||||
from DjangoBlog.utils import cache
|
||||
|
||||
|
||||
class MemcacheStorage(SessionStorage):
|
||||
def __init__(self, prefix='ws_'):
|
||||
self.prefix = prefix
|
||||
self.cache = cache
|
||||
|
||||
def key_name(self, s):
|
||||
return '{prefix}{s}'.format(prefix=self.prefix, s=s)
|
||||
|
||||
def get(self, id):
|
||||
id = self.key_name(id)
|
||||
session_json = self.cache.get(id) or '{}'
|
||||
return json_loads(session_json)
|
||||
|
||||
def set(self, id, value):
|
||||
id = self.key_name(id)
|
||||
self.cache.set(id, json_dumps(value))
|
||||
|
||||
def delete(self, id):
|
||||
id = self.key_name(id)
|
||||
self.cache.delete(id)
|
||||
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ServermanagerConfig(AppConfig):
|
||||
name = 'servermanager'
|
||||
@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class commands(models.Model):
|
||||
title = models.CharField('命令标题', max_length=300)
|
||||
command = models.CharField('命令', max_length=2000)
|
||||
describe = models.CharField('命令描述', max_length=300)
|
||||
created_time = models.DateTimeField('创建时间', auto_now_add=True)
|
||||
last_mod_time = models.DateTimeField('修改时间', auto_now=True)
|
||||
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
"""
|
||||
@version: ??
|
||||
@author: liangliangyy
|
||||
@license: MIT Licence
|
||||
@contact: liangliangyy@gmail.com
|
||||
@site: https://www.lylinux.org/
|
||||
@software: PyCharm
|
||||
@file: robot.py
|
||||
@time: 2017/8/27 上午1:55
|
||||
"""
|
||||
|
||||
from werobot import WeRoBot
|
||||
import re
|
||||
from werobot.replies import ArticlesReply, MusicReply, ImageReply
|
||||
from .MemcacheStorage import MemcacheStorage
|
||||
|
||||
robot = WeRoBot(token='lylinux', enable_session=True)
|
||||
|
||||
robot.config['SESSION_STORAGE'] = MemcacheStorage()
|
||||
|
||||
|
||||
@robot.handler
|
||||
def hello(message, session):
|
||||
count = 0
|
||||
if 'count' in session:
|
||||
count = session['count']
|
||||
count += 1
|
||||
session['count'] = count
|
||||
return str(count)
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
"""
|
||||
@version: ??
|
||||
@author: liangliangyy
|
||||
@license: MIT Licence
|
||||
@contact: liangliangyy@gmail.com
|
||||
@site: https://www.lylinux.org/
|
||||
@software: PyCharm
|
||||
@file: urls.py
|
||||
@time: 2017/8/27 上午2:27
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from werobot.contrib.django import make_view
|
||||
from .robot import robot
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^robot/', make_view(robot)),
|
||||
|
||||
]
|
||||
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Loading…
Reference in new issue