npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

owner-settings-bot

v0.4.1

Published

A bot that will modify the settings of other bots through text messaging

Downloads

5

Readme

owner-settings-bot

This bot allows an outsider to change the settings for a particular bot. When each bot is created, a unique passcode is also created to identify it. This passcode is used for this bot.

Annotated Source

Setup for ruby, shebang and library requires

#!/usr/bin/env ruby
#
#
require "./lib/greenbot.rb"
require 'mongo'
require 'awesome_print'

The bot works directly on the database. A mongo installed on the localhost and named greenbot is the default.

MONGO_URL = ENV['MONGO_URL'] || 'mongodb://127.0.0.1:27017/greenbot'

Open up the Bots collection in the database, go grab the local bots.

client = Mongo::Client.new(MONGO_URL)
Bots = client[:Bots]

Authenticate the inbound texter with the passcode, and use that to get the right bot to work with.

pin = ask("To get started, please provide your PIN")
pin.upcase!

bot = Bots.find({passcode: pin.strip}).first 

if bot.nil?
  say("I'm sorry, I cannot find that bot.")
  return
end

To make it easier for the texter, use a single letter to identify the settings to update. We add a sequential letter to the existing record set. We don't persist that in the database.

ALPHA = "ABCDEFGHIJKLMNOP"
index = 0
bot['settings'].sort! {|x,y| x['name'] <=> y['name']}
bot['settings'].each do |s|
  s['menu_choice'] = ALPHA[index]
  index += 1
end

Prepare the list of choices to present to the texter.

menu_choices = ''
bot['settings'].each do |s|
  menu_choices << s['menu_choice'] + ':' + s['name'] + " "
end
menu_choices << "Q:quit"

The main loop. We keep looping until somebody says Q. As the loop goes, collect the choice from the user. Then, display the current value, and offer a chance to update it. Keep that up until done.

loop do
  choice = ask("Please pick the setting to change: #{menu_choices}")
  choice.strip!
  choice.upcase!
  break if choice == 'Q' 
  setting = bot['settings'].find  do |s| 
    s['menu_choice'].eql?(choice)
  end

  if setting.nil?
    say("I could not find that setting")
  else
    new_val = ask("The current value is: #{setting['value']}. Please send a single mesasge with the new value, or empty to keep.")
    new_val.strip!
    Bots.update_one({"$and" => [{ "passcode" => pin.strip}, {"settings.name" => setting['name'] }]}, { '$set' =>  { "settings.$.value" => new_val }} )
  end
end 

And... we're done.

say("Thank you. Session ended.")