shop

maitain a shopping list (per user).

fbf.plugs.extra.shop.handle_got(bot, ievent)

arguments: <list of shop nrs> - remove items from shoplist

fbf.plugs.extra.shop.handle_shop(bot, ievent)

arguments: [<item>] - show shop list or add <item>

fbf.plugs.extra.shop.handle_shop2(bot, ievent)

add items to shop list

fbf.plugs.extra.shop.sayshop(bot, ievent, shoplist)

output shoplist

CODE

# fbf/plugs/common/shop.py
#
#

""" maitain a shopping list (per user). """

fbf imports

from fbf.utils.generic import getwho, jsonstring
from fbf.lib.users import users
from fbf.lib.commands import cmnds
from fbf.lib.examples import examples
from fbf.utils.pdol import Pdol

basic imports

import os

functions

def sayshop(bot, ievent, shoplist):
    """ output shoplist """
    if not shoplist: ievent.reply('nothing to shop ;]') ; return
    result = []
    teller = 0
    for i in shoplist: result.append('%s) %s' % (teller, i)) ; teller += 1
    ievent.reply("shoplist: ", result, dot=" ")

shop command

def handle_shop(bot, ievent):
    """ arguments: [<item>] - show shop list or add <item> """
    if len(ievent.args) != 0: handle_shop2(bot, ievent) ; return
    if ievent.user.state.data.shops: sayshop(bot, ievent, ievent.user.state.data.shops)
    else: ievent.reply("no shops")

def handle_shop2(bot, ievent):
    """ add items to shop list """
    if not ievent.rest: ievent.missing('<shopitem>') ; return
    else: what = ievent.rest
    if not ievent.user.state.data.shops: ievent.user.state.data.shops = []
    ievent.user.state.data.shops.append(what)
    ievent.user.state.save()
    ievent.reply('shop item added')

cmnds.add('shop', handle_shop, ['OPER', 'USER', 'GUEST'])
examples.add('shop', 'show shop items or add a shop item', '1) shop 2) shop bread')

got command

def handle_got(bot, ievent):
    """ arguments: <list of shop nrs> - remove items from shoplist """
    if len(ievent.args) == 0: ievent.missing('<list of nrs>') ; return
    try:
        nrs = []
        for i in ievent.args: nrs.append(int(i))
    except ValueError: ievent.reply('%s is not an integer' % i) ; return
    try: shop = ievent.user.state.data.shops
    except KeyError: ievent.reply('nothing to shop ;]') ; return
    if not shop: ievent.reply("nothing to shop ;]") ; return
    nrs.sort()
    nrs.reverse()
    teller = 0
    for i in range(len(shop)-1, -1 , -1):
        if i in nrs:
            try: del shop[i] ; teller += 1
            except IndexError: pass
    ievent.user.state.save()
    ievent.reply('%s shop item(s) deleted' % teller)

cmnds.add('got', handle_got, ['USER', 'GUEST'])
examples.add('got', 'emove items from shop list','1) got 3 2) got 1 6 8')

Table Of Contents

Previous topic

seen

Next topic

snarf

This Page