Giter VIP home page Giter VIP logo

brooklyn's Introduction

Brooklyn

Brooklyn is intended to be a protocol-independent chat-bridge to allow messages forward to and from various chat systems.

It supports Telegram and IRC for now but it's modular.

How to build

Brooklyn is written in Java and uses Maven to manage dependencies.

You can import the source in your favorite IDE in order to test it.

In production you should create a .jar and use it.

How to run it

The application needs a config file.

The default path is /etc/brooklyn/conf.yml but you can define a custom path, passing it as a first parameter (e.g. java -jar brooklyn.jar /new/path).

If you want to automate the process of configuring it on Debian 9 you can use brooklyn-ansible.

It uses log4j2 to log, see log4j2.xml for more infos. Consider using a log4j2-test.xml for debug purposes.

Telegram bot

Due to Telegram APIs limit you should create one bot for each telegram-related channel.

Remember to add the bot on each group you want to manage before adding it in your config file.

Rocket.Chat bot

You should use secure websocket (wss) instead of ws to connect the bot to a server, because messages are sent in plain text.

Remember to add the bot on each channel you want to manage before adding it in your config file.

conf.yml

This is a self-explanatory example of the configuration file.

bots:
 tbot:
    type: TelegramBot
    username: "JhonBot"
    password: "blablabla" # The token key
 ibot:
    type: IRCBot
    username: "skynet"
    password: "123456" # Optional
    host: "url.of.the.host.com"
 rbot:
    type: RocketChatBot
    host: "wss://chat.wikitolearn.org"
    username: "username"
    password: "password"
channels:
  ch1:
    bot: ibot
    name: "#channelname"
  ch2:
    bot: tbot
    name: "chat-id"
bridges:
  -
    - ch1
    - ch2
webserver:
  content-folder: "/var/www/html/"
  base-url: "http://localhost/"
db-uri: "jdbc:sqlite:" # You should not specify a path, so the file is temporary.

Webserver

You need also a webserver (e.g. nginx) to support attachments in protocols like IRC.

Don't forget to add read and write permissions for the content-folder. Otherwise the app won't work.

You should create a Cron job to remove images when you're running out of space.

An example might be

import os
import shutil
from datetime import date

contentFolder = "/var/www/html/"  # Folder to clean
maxSizeGB = 4  # Max folder size
nDaysBeforeExpiration = 1

# Get dir size
dirSizeBytes = 0
for dirPath, dirNames, fileName in os.walk(contentFolder):
    for f in fileName:
        fp = os.path.join(dirPath, f)
        dirSizeBytes += os.path.getsize(fp)

# Clean dir if it is too big
maxSizeBytes = maxSizeGB * 1024 * 1024 * 1024;
if dirSizeBytes > maxSizeBytes:
    # Iterate through years
    nYearsBeforeExpiration = nDaysBeforeExpiration / 30 / 12
    for d in os.listdir(contentFolder):
        fullDirPath = contentFolder + d
        if os.path.isdir(fullDirPath):
            if date.today().year - nYearsBeforeExpiration > int(d):
                print("Deleting " + fullDirPath)
                shutil.rmtree(fullDirPath)

    # Iterate through months
    nMonthsBeforeExpiration = nDaysBeforeExpiration / 30
    yearFolder = contentFolder + str(date.today().year).zfill(4)
    for d in os.listdir(yearFolder):
        fullDirPath = os.path.join(yearFolder, d)
        if os.path.isdir(fullDirPath):
            if date.today().month - nMonthsBeforeExpiration > int(d):
                print("Deleting " + fullDirPath)
                shutil.rmtree(fullDirPath)

    # Iterate through days
    monthFolder = os.path.join(yearFolder, str(date.today().month).zfill(2))
    for d in os.listdir(monthFolder):
        fullDirPath = os.path.join(monthFolder, d)
        if os.path.isdir(fullDirPath):
            if date.today().day - nDaysBeforeExpiration > int(d):
                print("Deleting " + fullDirPath)
                shutil.rmtree(fullDirPath)
else:
    print("Nothing to clean, there is enough space.")

License

This software is released under the GNU AGPL license.

brooklyn's People

Contributors

davide95 avatar aletundo avatar

Stargazers

 avatar Kristen McWilliam avatar Gábor Mihálcz avatar Kowalski Dragon avatar Nikhil Kumar Mishra avatar  avatar Enrico Lumetti avatar Hannah von Reth avatar Russell Greene avatar Srijan Agarwal avatar Cristian Baldi avatar Bryce Glover avatar  avatar Lion avatar Márk Bartos avatar

Watchers

Nicolás Alvarez avatar James Cloos avatar  avatar Lion avatar  avatar  avatar

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.