Giter Club home page Giter Club logo

telegram-shipit-bot's Introduction

Telegram Ship-it Bot

This bot uses the https://github.com/yagop/node-telegram-bot-api API.
Simple telegram bot with some random basic capabilities, see below for more information.
The bot also sends daily at 5:30 am the weather forecast for the provided location (see config.json).

Users

Hi there, I am a simple telegram bot named shipitbot. I can understand the following commands:

  • /burn - I will burn the witch!
  • /cat - I will send a random cat fact
  • /choose [option 1],..., [option n] - I will help you to choose between any amount of options
  • /decide [question] - I will decide for you (returns yes or no)
  • /doit - I will send a random picture related to the meme 'Just do it!'
  • /drawArt - I will send a random art from the early years of magic the gathering, cudos to magiccards.info
  • /drawCard - I will send a random card from the early years of magic the gathering, cudos to magiccards.info
  • /fact - I will send a random cat fact
  • /greet [name] - I will greet the provided name!
  • /help - I will display this message
  • /hype - I will start the hype train for you
  • /lorem - I will send a random picture provided by lorempixel.com
  • /math [formula] - I will send you a nicely rendered picture of your formula (I can even understand LaTeX commands, provided they are from the amsmath package)
  • /merge - I will send a random picture related to the word 'merge'
  • /motivation - I will send a randomly generated motivational image
  • /paper - I will play rock paper scissors with you
  • /rock - I will play rock paper scissors with you
  • /scissors - I will play rock paper scissors with you
  • /shipit - I will send a image related to the phrase 'ship it'
  • /slap [name] - I will slap the provided person a bit with large trout
  • /source - I will link you to the GitHub repository which contains my source files
  • /space - I will send you the current status of the hackerspace in Bamberg, Germany
  • /weather [location] - I will send you the weather forecast for today for the provided location (from wttr.in)
  • /who [message] - (should be used in a group) I will select a random user of a group and display the users name with the provided message

For Server-Maintainer

There is a shell script called "automated_deploy.sh".
This script starts the bot and waits for an update in the master branch. If an update is available, the bot process will be killed, the update will be merged and the bot will be started again.
If no update is available, your bot just works as expected.

But before starting the "automated_deploy.sh", copy your bot token into the config.json -> bottoken

Building the bot

The build process is done via npm.

Please read the following documentation to get familiar with npm:
https://docs.npmjs.com/

telegram-shipit-bot's People

Contributors

alerpcoder avatar cptpie avatar hahnieldahn avatar kerru avatar ydnax avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

telegram-shipit-bot's Issues

Rewrite function "\wer"

Using an array of hardcoded names is not a good solution in regards to maintainability and scalability.

I'd rather use something like "msg.from.first_name", as its used in the function "/choose".

Currently, i don't have time to rewrite it by myself.

Code cleanup: Limit variables to its scope

There are a lot of global variables that do not need a global scope, e.g. "loremSettings/doit/ship/editions/merge".

Maybe, we can think of a solution for variable "geste", because it is needed in three functions.

Sending daily weather forecast is not working

The bot is currently not sending the weather forecast at the designated time

Expected:

Bot is sending forecast at the designated time

Problems should be in the usage of sendWeather function within the scheduler (see line 134)

Add proper error handling

Now it is needed to handle errors properly (see #58), it is also necessary to generate errors scriptside because the log won't write these errors (see #55)

Stop bot if token is invalid

Actual state:
If the bot token is invalid, the log file will be flooded with an Error: ETELEGRAM: 404 Not Found and a massive error json.
over 200k log messages in a few seconds 👎

Desired state:
If the bot token is invalid, the bot shall stop and return with an error code.

More Options for /choose

We might want to enhance the /choose function to work with more (if possible n) options for better usability

Example input:

/choose foo, bar, why am i doing this, this is also a option

Desired output:

one of the 4 inputs

Suggestion: How to fill the users.json without explicit "/register" call

For every function the bot offers (e.g. /stone, /choose) we save the values "msg.from.first_name", "msg.from.username" and add a subroutine in every function that adds the name to the file "users.json".

e.g. /choose for example

bot.onText(/\/choose (.+), (.+)/,(msg, input) => {
  var answer = Math.random() >= 0.5 ? input[1] : input[2];
  bot.sendMessage(msg.chat.id, "@shipitbot has chosen *"+answer+"* for "+msg.from.first_name,{parse_mode : "Markdown"});
  });

could be written as:

bot.onText(/\/choose (.+), (.+)/,(msg, input) => {
  addToUsersJSON(msg.from.first_name, msg.from.username);

  var answer = Math.random() >= 0.5 ? input[1] : input[2];
  bot.sendMessage(msg.chat.id, "@shipitbot has chosen *"+answer+"* for "+ msg.from.first_name,{parse_mode : "Markdown"});
  });

Therefore we would have to write a function called addToUsersJSON that could look like following:

function addToUsersJSON(firstname, username) {
  var myObject=require('./users');
  for (i in myObject.users){
    if (myObject.users[i].username==username){
      var contains = true;
    };
  };

  if (!contains){
    myObject['users'].push({'username': username,'first': firstname});
  };
  var json = JSON.stringify(myObject);
  fs.writeFile('users.json',json);
}

Don't expect the above code to work out of the box. The code above is untested!

Keep consistency with language

There are functions with english names like "decide/choose/etc.".
But, there are also functions with german names like "wer/schere/stein/papier".
Furthermore, there are function names that are non describing, like /marius

Maybe, we should keep consistency with the language?

Ignore fog warnings

The weather warning feature spams too much in case of fog

It might be useful to check if the headline contains the keyword "Nebel" anderen then don't send the warning

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.