示例#1
0
def make_tags():
    if get_option('endermanUnpickable'):
        write_enderman_unpickable()
    if get_option('mushroomGrowable'):
        write_mushroom_growable()
    if get_option('variantedStoneRecipe'):
        write_stone()
    if get_option('naturalSoul'):
        write_natural_soul()
示例#2
0
 def test_reset_option(self):
     set_option('opt', 'val')
     reset_option('opt', 'new_val')
     value = get_option('opt', 'wrong value')
     self.assertEqual(value, 'new_val')
     
     set_option('opt', 'val', self.user)
     reset_option('opt', 'new_val', self.user)
     value = get_option('opt', 'wrong value', user=self.user)
     self.assertEqual(value, 'new_val')
示例#3
0
 def test_default_value(self):
     value = get_option('opt', 'val')
     self.assertEqual(value, 'val')
     option = CustomOption.objects.get(name='opt')
     self.assertEqual(option.value, 'val')
     
     value = get_option('opt', 'val', self.user)
     self.assertEqual(value, 'val')
     option = CustomOption.objects.get(name='opt', user=self.user)
     self.assertEqual(option.value, 'val')
示例#4
0
def go_back_start(update: Update, context: CallbackContext) -> int:
    update.message.reply_chat_action("typing")
    answer = update.message.text

    if answer == GO_BACK_TO_QUESTION:
        option = get_option(context.user_data['option'])
    else:
        option = get_option("/restart")

    enter_option(option, update, context)

    return HANDLE_RESPONSE
示例#5
0
def should_reply(si, sn, ci, cn, ui, un, txt, server, channel, author):
    opt_mention_only = options.get_option(si, ci, 'mention_only')
    opt_extra_prefix = options.get_option(si, ci, 'extra_prefix')

    keywords = ["<@%s>" % client.user.id, "<@!%s>" % client.user.id]

    # ignore empty messages
    if not txt:
        return (False, txt)

    # never reply to own messages
    if ui == client.user.id:
        return (False, txt)

    # ignore bots by default
    if author.bot and options.get_option(si, ci, 'reply_to_bots') == 0:
        return (False, txt)

    member = None
    if server:
        member = server.get_member(client.user.id)

    # check send perms
    if channel and member and (
            not channel.permissions_for(member).send_messages):
        return (False, txt)

    if opt_extra_prefix != "" and txt.lower().startswith(
            opt_extra_prefix.lower()):
        return (True, txt[len(opt_extra_prefix):])

    if opt_mention_only <= 0:
        keywords.append(Config.get('Chat', 'Keyword').lower())
        if member and member.nick:
            keywords.append(member.nick.lower())


#  print("kw: ", keywords)
    if options.get_option(si, ci, 'prefix_only') <= 0:
        for kw in keywords:
            if kw in txt.lower():
                return (True, txt)
    else:
        for kw in keywords:
            if txt.lower().startswith(kw):
                return (True, txt)

    prob = options.get_option(si, ci, 'reply_prob')
    if (uniform(0, 1) < prob):
        return (True, txt)
    return (False, txt)
示例#6
0
    def test_reset_option(self):
        """
        The reset_option() function should remove all previous definitions
        of an option and reset its value
        """
        set_option('opt', 'val')
        reset_option('opt', 'new_val')
        value = get_option('opt', 'wrong value')
        self.assertEqual(value, 'new_val')

        set_option('opt', 'val', self.user)
        reset_option('opt', 'new_val', self.user)
        value = get_option('opt', 'wrong value', user=self.user)
        self.assertEqual(value, 'new_val')
示例#7
0
    def test_default_value(self):
        """
        The second parameter of get_option() function is a default value for
        an option and it should be used in case of getting option that hasn't
        been set yet
        """
        value = get_option('opt', 'val')
        self.assertEqual(value, 'val')
        option = CustomOption.objects.get(name='opt')
        self.assertEqual(option.value, 'val')

        value = get_option('opt', 'val', self.user)
        self.assertEqual(value, 'val')
        option = CustomOption.objects.get(name='opt', user=self.user)
        self.assertEqual(option.value, 'val')
示例#8
0
 def get_option(self, name):
     """
     Returns value of the option with specified name or returns result
     of the return_func function declared for plugin's option with this name.
     """
     from options import get_option
     option = self.options().get(name)
     if option:
         value = get_option(name, option.get('default', ''))
         return_func = option.get('return_func')
         if return_func:
             return return_func(value)
     else:
         value = get_option(name)
     return value
示例#9
0
 def get_option(self, name):
     """
     Returns value of the option with specified name or returns result
     of the return_func function declared for plugin's option with this name.
     """
     from options import get_option
     option = self.options().get(name)
     if option:
         value = get_option(name, option.get('default', ''))
         return_func = option.get('return_func')
         if return_func:
             return return_func(value)
     else:
         value = get_option(name)
     return value
示例#10
0
def handle_topic_selection_inline(update: Update,
                                  context: CallbackContext) -> int:
    query = update.callback_query
    query.answer()
    option = get_option(context.user_data['option'])
    next_option = option.handle_response(update, context, get_option)
    enter_option(next_option, update, context)
    return HANDLE_RESPONSE
示例#11
0
 def get_option(self, name, widget):
     """
     Returns value of the option with specified name or returns result
     of the return_func function declared for widget's option with this name.
     """
     from options import get_option
     option = self.options(widget).get(name)
     if option:
         if not option.has_key('default'):
             raise DefaultValueNotFound(_("Default value for option '%s' "
                                          "has not been provided") % name)
         value = get_option(name, option.get('default'))
         return_func = option.get('return_func')
         if return_func:
             return return_func(value)
     else:
         value = get_option(name, '')
     return value
示例#12
0
 def join(self, groupchat, nick=None):
  if nick == None: nick = self.get_nick(groupchat)
  else: self.set_nick(groupchat, nick)
  groupchat = groupchat.replace("\n", "")
  groupchat = self.bot.g.setdefault(groupchat, new_room(self.bot, groupchat))
  p = domish.Element(('jabber:client', 'presence'))
  p['to'] = u'%s/%s' % (groupchat.jid, nick)
  p.addElement('status').addContent(options.get_option(groupchat.jid, 'status', config.STATUS))
  p.addElement('x', 'http://jabber.org/protocol/muc').addElement('history').__setitem__('maxchars', '0')
  self.bot.wrapper.send(p)
  q = self.load_groupchats()
  if not (groupchat.jid in q): self.dump_groupchats(q+[groupchat.jid])
示例#13
0
async def send_option_list(si, ci, channel):
    emb = discord.Embed(description="Options, set using /!set")
    for opt in options.options.values():
        if opt.settable:
            v = 'type: ' + opt.type.__name__
            if opt.default_group == opt.default_user:
                v += '\ndefault: %s' % opt.default_group
            else:
                v += '\nuser default: %s\nchannel default: %s' % (
                    opt.default_user, opt.default_group)
            v += '\ncurrent value: %s' % options.get_option(si, ci, opt.name)
            v += '\n%s' % opt.description
            emb.add_field(name=opt.name, value=v)
    await channel.send(embed=emb)
示例#14
0
    def get_option(self, name, widget):
        """
        Returns value of the option with specified name or returns result
        of the return_func function declared for widget's option with this name.
        """
        from options import get_option
        self.user = get_user_objects(None,widget)
        if self.username:
			for user in self.username:
				user_name = get_user_objects(user, widget)
				self.user_list.append(user_name)
        option = self.options(widget).get(name)
        if option:
            if not option.has_key('default'):
                raise DefaultValueNotFound(_("Default value for option '%s' "
                                             "has not been provided") % name)
            value = get_option(name, option.get('default'))
            return_func = option.get('return_func')
            if return_func:
                return return_func(value)
        else:
            value = get_option(name, '')
        return value
示例#15
0
文件: muc.py 项目: setazer/freq-bot
 def join(self, groupchat, nick=None, password=None):
  if nick == None: nick = self.get_nick(groupchat)
  else: self.set_nick(groupchat, nick)
  groupchat = groupchat.replace('\n', '')
  groupchat = self.bot.g.setdefault(groupchat, new_room(self.bot, groupchat))
  p = domish.Element(('jabber:client', 'presence'))
  p['to'] = u'%s/%s' % (groupchat.jid, nick)
  p.addElement('status').addContent(options.get_option(groupchat.jid, 'status',
  config.STATUS).replace('%VERSION%', self.bot.version_version))
  p.addElement('show').addContent(options.get_option(groupchat.jid, 'show', config.SHOW))
  xElem = domish.Element(('http://jabber.org/protocol/muc', 'x'))
  if password != None:
   xElem.addElement('password').addContent(password)
  p.addChild(xElem)
  cElem = domish.Element(('http://jabber.org/protocol/caps', 'c'))
  cElem['hash'] = 'sha-1'
  cElem['ver'] = self.bot.caps
  cElem['node'] = 'http://www.freq-bot.net/'
  p.addChild(cElem)
  self.bot.wrapper.send(p)
  q = self.load_groupchats()
  if not (groupchat.jid in q): self.dump_groupchats(q+[groupchat.jid])
  return groupchat
示例#16
0
文件: muc.py 项目: cobrab11/freq-bot
 def join(self, groupchat, nick=None, password=None):
  if nick == None: nick = self.get_nick(groupchat)
  else: self.set_nick(groupchat, nick)
  groupchat = groupchat.replace('\n', '')
  groupchat = self.bot.g.setdefault(groupchat, new_room(self.bot, groupchat))
  p = domish.Element(('jabber:client', 'presence'))
  p['to'] = u'%s/%s' % (groupchat.jid, nick)
  p.addElement('status').addContent(options.get_option(groupchat.jid, 'status',
  config.STATUS).replace('%VERSION%', self.bot.version_version))
  p.addElement('show').addContent(options.get_option(groupchat.jid, 'show', config.SHOW))
  xElem = domish.Element(('http://jabber.org/protocol/muc', 'x'))
  if password != None:
   xElem.addElement('password').addContent(password)
  p.addChild(xElem)
  cElem = domish.Element(('http://jabber.org/protocol/caps', 'c'))
  cElem['hash'] = 'sha-1'
  cElem['ver'] = self.bot.caps
  cElem['node'] = 'http://www.freq-bot.net/'
  p.addChild(cElem)
  self.bot.wrapper.send(p)
  q = self.load_groupchats()
  if not (groupchat.jid in q): self.dump_groupchats(q+[groupchat.jid])
  return groupchat
示例#17
0
 def join(self, groupchat, nick=None, password=None):
     if nick == None: nick = self.get_nick(groupchat)
     else: self.set_nick(groupchat, nick)
     groupchat = groupchat.replace('\n', '')
     groupchat = self.bot.g.setdefault(groupchat,
                                       new_room(self.bot, groupchat))
     p = domish.Element(('jabber:client', 'presence'))
     p['to'] = u'%s/%s' % (groupchat.jid, nick)
     p.addElement('status').addContent(options.get_option(groupchat.jid, 'status', \
     config.STATUS).replace('%VERSION%', self.bot.version_version))
     p.addElement('x', 'http://jabber.org/protocol/muc').addElement(
         'history').__setitem__('maxchars', '0')
     self.bot.wrapper.send(p)
     q = self.load_groupchats()
     if not (groupchat.jid in q): self.dump_groupchats(q + [groupchat.jid])
     return groupchat
示例#18
0
def handle_topic_selection(update: Update, context: CallbackContext) -> int:
    update.message.reply_chat_action("typing")

    option = get_option(context.user_data['option'])
    next_option = option.handle_response(update, context, get_option)

    if not next_option:
        update.message.reply_animation(
            animation=HUH_FILE_ID,
            reply_markup=ReplyKeyboardMarkup([["Ja"], [GO_BACK_TO_QUESTION]],
                                             one_time_keyboard=True),
            caption=
            "Das habe ich nicht verstanden, möchtest du ein anders Thema auswählen?"
        )

        return GO_BACK_TO_START

    enter_option(next_option, update, context)
示例#19
0
def make_recipe():
    if get_option('smeltableProducts'):
        for material, result in smeltables:
            for kind in smeltable_types:
                write_smeltable_recipes(material, result, kind)
        write_smeltable_recipes('stone', 'smooth_stone', 'slab')

    if get_option('vineableProducts'):
        for material, result in vineables:
            for kind in vineable_types:
                write_vineable_recipes(material, result, kind)

    if get_option('upgradableTools'):
        for material, addition, result in tool_upgradables:
            for kind in TOOL_TYPES:
                write_upgradable_recipes(material, addition, result, kind)

        for material, addition, result in armor_upgradables:
            for kind in ARMOR_TYPES:
                write_upgradable_recipes(material, addition, result, kind)

    if get_option('decraftableProducts'):
        for material, result, amount in decraftables:
            write_decraftable_recipes(material, result, amount)

    if get_option('shapelessRecipes'):
        for ingredients, result, amount in shapelesses:
            write_shapeless_recipes(ingredients, result, amount)

    if get_option('craftableSaplings'):
        for material, result in saplings:
            write_sapling_recipes(material, result)

    if get_option('craftableOres'):
        for material, result, stone, pattern in ores:
            write_ore_recipes(material, result, stone, pattern)

    if get_option('betterSmeltingOres'):
        for material, result in zip(ORES, SMELTED_MINERALS):
            write_better_smelting_ore_recipes(material, result)
示例#20
0
 def get_option(self, k, d=None):
  return options.get_option(self.jid, k, d)
示例#21
0
async def on_message(message):
    start_time = time()
    msgcolor = ''
    ci, cn = channelidname(message.channel)
    si, sn = serveridname(message.guild)
    ui = message.author.id
    un = message.author.name
    txt = message.content

    if txt == "":
        return

    if options.get_option(si, ci, 'blacklisted') > 0:
        return

    cansend = can_send(message.guild, message.channel)

    channel_ignored = False
    if message.author.bot:
        msgcolor = '\033[34m'
    if options.get_option(si, ci, 'ignore_channel') > 0:
        channel_ignored = True
        msgcolor = '\033[90m'
    if not cansend:
        msgcolor = '\033[31m'
    if not message.guild:
        msgcolor = '\033[96m'
    if ui == client.user.id:
        msgcolor = '\033[92m'

    if not channel_ignored:
        print(msgcolor +
              ('%s/%s %s/%s %s/%s : %s' %
               (sn, si, cn, ci, message.author.name, message.author.id, txt)) +
              '\033[0m')

    if message.id in cmd_replies:
        print('(not logging)')
        return
    log_chat(message, si, sn, ci, cn, ui, un, txt, message.author.bot)
    for u in message.mentions:
        log_mention(u.id, u.name, u.mention)
    for r in message.role_mentions:
        log_role(si, r.id, r.name, r.mention)

    if not cansend:
        return

    if ui == client.user.id:
        return

    if channel_ignored == True:
        return

    if txt.startswith('/!') and message.author.bot:
        return

    if txt.startswith('/!help'):
        await message.channel.send(embed=make_help())

    elif txt.startswith('/!set '):
        if message.guild and not message.author.permissions_in(
                message.channel).manage_channels:
            cmd_replies.add((await message.channel.send(
                "< only people with manage_channels permission can set options >"
            )).id)
            return
        splt = txt.split()
        if (len(splt) == 3):
            opt = splt[1]
            val = splt[2]
            try:
                options.set_option(ci, opt, val)
                await message.channel.send("< option %s set to %s >" %
                                           (opt, val))
            except options.OptionError as oe:
                await message.channel.send("< %s >" % str(oe))
        elif (len(splt) == 2):
            opt = splt[1]
            try:
                options.set_option(ci, opt, None)
                await message.channel.send("< option %s unset >" % (opt, ))
            except options.OptionError as oe:
                await message.channel.send("< %s >" % str(oe))
        else:
            cmd_replies.add((await message.channel.send(
                "< invalid syntax, use /!set option value >")).id)
            return

    elif txt.startswith('/!clear'):
        options.optioncache.clear()
        print('options cache flushed')

    elif txt.startswith('/!badword '):
        if message.guild and not message.author.permissions_in(
                message.channel).manage_channels:
            await message.channel.send(
                "< only people with manage_channels permission can change badwords >"
            )
            return
        splt = txt.split(' ', 1)
        bw = splt[1]
        bws = badword_get(si or ci)
        if bw in bws:
            badword_del(si or ci, bw)
            await message.channel.send("< badword %s deleted >" % (bw))
        else:
            badword_add(si or ci, bw, ui)
            await message.channel.send("< badword %s added >" % (bw))

    elif txt == '/!badword':
        bws = badword_get(si or ci)
        await message.channel.send("< badwords: %s >" % repr(bws))

    elif txt == '/!list_options':
        await send_option_list(si, ci, message.channel)

    else:
        queued = await nn.queued_for_key(str(ci))
        if queued > 32:
            print('Dropping message, %d messages queued' % queued)
            return

        (shld_reply, new_text) = should_reply(si, sn, ci, cn, ui, un, txt,
                                              message.guild, message.channel,
                                              message.author)

        if (not message.author.bot) or (len(txt) <= options.get_option(
                si, ci, 'max_bot_msg_length')):
            txt2 = new_text
            for u in message.mentions:
                txt2 = txt2.replace(u.mention, '@' + u.name)
                txt2 = txt2.replace('<@!%d>' % u.id, '@' + u.name)
            for r in message.role_mentions:
                txt2 = txt2.replace(r.mention, '@' + r.name)
            for c in message.channel_mentions:
                txt2 = txt2.replace(c.mention, '#' + c.name)
            if txt2 != new_text:
                print(" interpreted as %s" % txt2)
            await nn.put(str(ci), txt2)

        if shld_reply:
            if ci not in currently_sending:
                currently_sending[ci] = 0
            if currently_sending[ci] > 8:
                print('%d messages being sent, not responding' %
                      currently_sending[ci])
                return
            currently_sending[ci] += 1
            try:
                async with message.channel.typing():
                    rpl_txt = await nn.get(str(ci),
                                           bad_words=badword_get(si or ci))
                    if rpl_txt == '':
                        print('ignoring empty reply')
                        return
                    rpl_msg = await message.channel.send(
                        rpl_txt,
                        allowed_mentions=discord.AllowedMentions(
                            everyone=False))
            finally:
                currently_sending[ci] -= 1
            end_time = time()
            reply_delay = end_time - start_time
            if reply_delay > 20:
                await rpl_msg.edit(content=rpl_txt +
                                   ('\n*reply delayed by %f seconds*' %
                                    (reply_delay)))
                print('message took %f seconds to generate' % (reply_delay))
示例#22
0
文件: muc.py 项目: setazer/freq-bot
 def get_nick(self, groupchat):
  return options.get_option(groupchat, 'nick', config.NICK)
示例#23
0
文件: lang.py 项目: setazer/freq-bot
def getLang(jid):
 jid = jid.split('/')[0]
 return options.get_option(jid, 'lang', config.LANG)
示例#24
0
 def get_nick(self, groupchat):
     return options.get_option(groupchat, 'nick', config.NICK)
示例#25
0
 def get_option(self, k, d=None):
  return options.get_option(self.jid, k, d)
示例#26
0
def getLang(jid):
    jid = jid.split('/')[0]
    return options.get_option(jid, 'lang', config.LANG)
示例#27
0
 def test_set_and_get_option(self):
     set_option('opt', 'val')
     value = get_option('opt', 'wrong value')
     self.assertEqual(value, 'val')
     unset_option('opt')
示例#28
0
import e32

# App configuration
apiKey = 'e8f0dd71d905f815af42b4752de411b5' 
secret = 'd64c0294efd97ddd'

#token='c620b829b667a3e8c828dd28bb7cc132017029fc'


if not db.init(app_path + u"rtm.db"):
  options.init()
  #TODO more db initialization

rtm = pyrtm.RTM(apiKey, secret)

rtm.token = options.get_option('token')

if not rtm.token:
  frob = options.get_option('frob')
  if frob:
    rtm.frob = frob
    try:
      rtm.getToken()
      options.set_option('token',rtm.token)
    except RTMAPIError:   
      frob = rtm.getNewFrob()
  else:
    frob = rtm.getNewFrob()

  if not token: # we did not get token by frob
    options.set_option('frob',frob)
示例#29
0
def getLang(jid):
 jid = jid.split("/")[0]
 return options.get_option(jid, "lang", config.LANG)