GithubHelp home page GithubHelp logo

techgaun / ex_mustang Goto Github PK

View Code? Open in Web Editor NEW
70.0 6.0 9.0 583 KB

:sparkles: A simple, clueless bot

License: Apache License 2.0

Elixir 100.00%
elixir slack-bot bot slack responder standup-reminder uptime-check uptime-monitoring hacktoberfest

ex_mustang's Introduction

ex_mustang

A simple, clueless bot

Mustang

ExMustang is a bot for Slack written in Elixir. While ExMustang is written for Slack, the responder modules should work fine with other Hedwig adapters as well. If you like Mustang, please use Mustang as bot image if possible :)

Warning: This is a work in progress.

Example

Example

Example

Setup

Create a Slack bot user from here. You will receive an API token you can use. Set the SLACK_API_TOKEN environment variable and you should be good to go.

You can run this bot as below:

export SLACK_API_TOKEN="<SLACK_API_TOKEN>"
mix run --no-halt

A sample runner configuration looks like below:

export SLACK_API_TOKEN="<SLACK_API_TOKEN<"
export GITHUB_TOKEN="<GITHUB_TOKEN>"
export GOOGLE_API_KEY="<GOOGLE_API_KEY>"
export GIPHY_API_KEY="<GIPHY_API_KEY>"
export STANDUP_CHANNEL="scrum"
export GH_CHANNEL="github"
export PWN_CHANNEL="critical"
export UPTIME_CHANNEL="critical"
export SLACK_INVITEALL_TOKEN="<SLACK_INVITEALL_TOKEN>"

mix run --no-halt

For using ex_mustang with multiple slack teams, you can use MIX_ENV by creating config files such as yourteam.exs and run as MIX_ENV=yourteam mix run --no-halt

Scheduled Notifications

Github Pull Requests Watcher

You can configure github token by setting GITHUB_TOKEN. Also, you can pass list of repos to watch by updating config. There are bunch of other stuffs you can configure such as schedule (which follows cron format), slack channel and thresholds.

Standup Reminder

The standup reminder reminds us when its standup time. Our nature is that we either forget track of time or are too lazy to remember about it. This does not make you better at attending standup but is more of a satire for us. You can configure message and other bunch of stuffs on config

Have I Been Pwned Checker

The hibp checker can check list of accounts against haveibeenpwned.com by using ExPwned. You can set the appropriate configuration on config.exs.

# config below runs hibp check once a day and posts if any found breach to configured slack channel
config :ex_mustang, ExMustang.Responders.Pwned,
  schedule: "0 * */1 * *",
  enabled: true,
  accounts: [
    "[email protected]",
    "[email protected]"
  ],
  slack_channel: System.get_env("PWN_CHANNEL") || "general"

Uptime Monitoring

ExMustang supports simple uptime monitoring and can perform periodic uptime checks against given set of endpoints. The config block looks like below:

config :ex_mustang, ExMustang.Responders.Uptime,
  schedule: "*/5 * * *",
  enabled: true,
  endpoints: [
    [
      uri: "https://api.brighterlink.io/status", status_code: 200, content: ~s("msg":"ok"), method: "GET",
      content_type: "application/json", req_headers: [{"User-Agent", "ExMustang"}], timeout: 20_000
    ]
  ],
  slack_channel: System.get_env("UPTIME_CHANNEL") || "general"

The endpoints section is where you define the endpoints you're willing to perform uptime check against.

  • uri - the endpoint to hit
  • status_code - expected status code
  • content - expected response body content (supports both string and regular expression)
  • method - one of GET, POST, PUT, PATCH and DELETE
  • body - body to send as part of POST, PUT or PATCH requests
  • content_type - expected content type header value
  • req_headers - list of tuples of request headers to send
  • timeout - maximum timeout before request fails

Random Quote of the Day

ExMustang can send a quote as specified in schedule. You can configure schedule from config.exs and you can specify QUOTE_CHANNEL env-var. If QUOTE_CHANNEL is not specified, the quotes are sent to general channel by default.

Responders

Currently, there are following responders and these should ideally work with any Hedwig adapters:

  • ExMustang.Responders.GMap - gives you google maps search result for your search queries.
  • ExMustang.Responders.Pwned -
  • ExMustang.Responders.Quote - gives you random funny quote
  • ExMustang.Responders.Slap - slaps another user
  • ExMustang.Responders.Time - gives time on given timezone (without timezone, uses local timezone of machine ExMustang is running on)
  • ExMustang.Responders.TimeConvert - converts given unix timestamp to ISO8601 format
  • ExMustang.Responders.EncodeDecode - encoding/decoding tools
  • ExMustang.Responders.Isup - checks if a site is up or not via isitup.org API
  • ExMustang.Responders.RandomInsult - insults a user with random insults from randominsults.net
  • ExMustang.Responders.HTTPCat - gets a cat for corresponding http status code
  • ExMustang.Responders.Howdoi - tries to find answer for programming questions
  • ExMustang.Responders.CommitMsg - Get random commit messages from http://whatthecommit.com/index.txt
  • ExMustang.Responders.CLIFu - Gets clifu gems from http://www.commandlinefu.com
  • ExMustang.Responders.Whois - performs a whois query using https://dnsquery.org
  • ExMustang.Responders.GitTip - get a random git tip (with support for keywords)
  • ExMustang.Responders.Birthday - send a happy birthday to the mentioned user
  • ExMustang.Responders.InviteAll - invite all members (of optionally given channel)
  • ExMustang.Responders.UrbanDictionary - presents urban dictionary word of the day
  • ExMustang.Responders.Giphy - renders gif using https://giphy.com

For Google Maps search, you have to set GOOGLE_API_KEY which has access to call google places api.

mustang help - Displays all of the help commands that mustang knows about.
mustang help <query> - Displays all help commands that match <query>.
gmap <search_term> - Replies with the information from google places/maps.
pwned <search_account> - Checks to see if an account has been breached or not
quote - Replies with a random quote.
slap - Slaps the user. Format: slap <username> | me
time - get time in a given timezone
unix2iso <unix_timestamp> - Converts given unix timestamp to ISO format (Auto-replies for values that look like timestamps)
b64encode <content> - base64 encoding of given text content
b64decode <content> - base64 decoding of given text content
isitup <domain> - checks if given domain is up or not
insult me|<username> - insults given username with random insults
httpcat <status_code> - get http status code cat for given value
howdoi <query> - tries to find solution on the given query
commitmsg - get a random commit message
clifu [search_word] - get clifu gem (gives random clifu if no keyword is passed)
whois <domain> - gives whois query for given domain
gittip [keyword] - Get a random git tip for given keyword
happy birthday <me|@user> - Send happy birthday message to the user mentioned
hdeploy <app-name> - Deploys configured branch to the given app
inviteall [src_channel] - invite all the members of source channel
giphy [search_term] - Tries to find a GIF matching search_term (gives random gif if no search_term is provided)

Heroku Deployment

For heroku deployment to work, you need to specify the following configurations:

  • HEROKU_GITHUB_TOKEN or GITHUB_TOKEN
  • HEROKU_TOKEN which is an API key you can get from here
  • mapping of apps in your config which is a tuple of heroku app name and map of repo and branch

An example config looks like below:

config :ex_mustang, ExMustang.Responders.HerokuDeploy,
  github_token: System.get_env("HEROKU_GITHUB_TOKEN") || System.get_env("GITHUB_TOKEN"),
  token: System.get_env("HEROKU_TOKEN"),
  apps: [
    {"casa-core-stage", %{repo: "casaiq/core", branch: "master"}}
  ]

InviteAll Responder

The invite all responder requires you to provide a token of a non-bot and non-guest slack team member because thats how the slack api works. You can get your personal tokens from HERE

Changelog

The detail changelog is available HERE

About Mustang

Mustang (pronounced like moostang not like the Ford Mustang; I don't know phonetics) is my best friend whom I had to leave back in Nepal. After surviving April 2015 Earthquake, we lived together for a while and I had to leave him back in Nepal. Below is the pic post-earthquake.

Mustang and Me

ex_mustang's People

Contributors

jasonsoares avatar techgaun avatar theodowling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ex_mustang's Issues

whois is not working

it seems that whois is not working. gives I could not perform whois on domain for every domain

split out docs for responders

The number of responders is increasing now. So, we should split out the responders into separate doc and reference from readme

random gifs

maybe be better about getting random gifs.. well mustang yet does not have any gif stuff so that should be built first.. this might be little harder unless we can use an API from giphy or something similar so we can filter by things like nsfw..

if we use giphy api, one fun thing would be to hear common exclamation words and then respond with GIPHY TRANSLATE

qotd

Quote of the day at given time

add ability to run scripts via cron

  • have bash files that have the line starting with

# ex_mustang: <cron format here> <optional slack channel>

and be able to run and report the output to the specified slack channel

fix timestamp extra intelligence

for example: paste this: https://twitter.com/danielsing3r/status/818221826685812736 and it thinks there's a timestamp in there.

Auto-branch updater for open pull requets

If pull requests are open and need to be updated with base branch, bot can basically update the branch in case of no merge conflict.

https://developer.github.com/v3/repos/merging/
{
 "base": "your_branch",
 "head": "master",
 "commit_message": "Merge master into branch"
}

fix whois responder

whois responder has techgaun.com in its regex which causes it to fail for all domains other than techgaun.com

simple uptime monitoring

  • list of endpoints to watch
  • monitor for response content, http status code, response type, optionally allow passing header tuples
  • does not have to be too fancy; just a simple implementation

ability to specify custom additional config

the reason I think we need this is so that we can specify different configs for different slack channels.. maybe the concept of env can be applied so you have envs with configs such xyz.exs or abc.exs where xyz and abc are the slacks for two different groups and MIX_ENV=xyz and MIX_ENV=abc would just load the right config that way. Will have to take a look

aliases for heroku apps

add ability to specify aliases for heroku apps so that we can deploy using one of those aliases.
eg. if api is alias to long-name-of-app, we can just say hdeploy api

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.