Code Monkey home page Code Monkey logo

oakbot's Introduction

OakBot

codecov.io Known Vulnerabilities

OakBot is a chat bot for Stack Overflow Chat that's written in Java. It is named after the first name given to the Java programming language before it became "Java".

OakBot is most active in the Java chat room.

Requirements

  • Java 17
  • Maven (for building)

Build Instructions

To build the project, first clone and install the SOChat4j library:

git clone https://github.com/mangstadt/sochat4j.git
cd sochat4j
mvn install

Then, inside of the cloned OakBot folder, run mvn package. This command will build the project and package it into an executable, shaded JAR. A shaded JAR file contains all of the project's dependencies. The shaded JAR file is saved here: target/OakBot-VERSION.jar.

Deploy Instructions

  1. Copy the following files to the server. Put them in the same directory:
    1. target/OakBot-VERSION.jar: The executable, shaded JAR file that contains OakBot's code and dependencies.
    2. bot-context.xml: This file contains configuration data and command definitions. A sample file is located in the root of this project.
    3. logging.properties (optional): The configuration file for the Java Logging API. A sample file is located in the root of this project.
  2. Run OakBot: java -jar OakBot-VERSION.jar
  3. Once the bot has fully started up, it will instruct you to press Ctrl+Z, then type the bg command. In Linux, this will move the program into the background and free up the shell.

db.json

This is the file OakBot uses to persist information, such as how many commands it has responded to and what rooms it has joined. It is located in the bot's working directory. The file will automatically be created if it doesn't exist.

bot-context.xml

Contains various configuration settings for the bot. Open the sample bot-context.xml file at the root of this project for a description of each setting.

OakBot must be restarted if any of these settings are changed while OakBot is running.

Adding/Removing Commands

All of the bot's commands are defined in the bot-context.xml file.

Commands can be added by creating a class that extends the Command interface, and then adding the class to bot-context.xml (you must also, of course, include your class in the Java classpath when running the bot).

This file uses Spring's IoC container library.

All of OakBot's commands are listed on the wiki.

CLI Arguments

Argument Description
--context=PATH The path to the Spring application context XML file that contains the bot's configuration settings and commands (defaults to "bot-context.xml"). Note: Absolute paths must be prefixed with "file:".
--mock Runs the bot using a mock chat connection for testing purposes.

A text file will be created in the root of the project for each chat room the bot is configured to connect to. These files are used to "send" messages to the mock chat rooms. To send a message, type your message into the text file and save it.

Messages are entered one per line. Multi-line messages can be entered by ending each line with a backslash until you reach the last line. You should only append onto the end of the file; do not delete anything. These files are re-created every time the program runs.

All messages that are sent to the mock chat room are displayed in stdout (this includes your messages and the bot's responses).
--quiet If specified, the bot will not output a greeting message when it starts up.
--version Prints the version of this program.
--help Prints descriptions of each argument.

Questions/Feedback

Please submit all questions, bug reports, and feature requests to the issue tracker.

oakbot's People

Contributors

abhinayagarwal avatar dependabot[bot] avatar lunarwatcher avatar mangstadt avatar unihedro 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oakbot's Issues

Some javadoc links are broken

/javadoc PrintStream#printf (1) produces: http://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#printf-java.lang.String-java.lang.Object:A- while the link in the Java Documentation is https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#printf-java.lang.String-java.lang.Object...-

This seems to be because of varargs vs array but weirdly enough /javadoc Arrays#asList produces https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-java.lang.Object:A- which correctly links.

Maybe the difference here is generic varargs to "classed" varargs?

Filter specific (breaking) unicode chars

This started with \u202e, which is the RTL force character. In the help command, it results in:

image

the yay command at the end is in fact \u202eyay, and where the \u202e char is, all the other text is flipped too. But this could happen with other unicode chars as well, like the 0-width space char \u200b. if a command is taught as \u200bcommandname (where \u200b is replaced with the char itself. write copy("\u200b") in the browser console to get it), the command ends up as commandname, but cannot be untrained because of the extra, invisible char.

Obviously, you can't protect against all the chars, but at least taking care of \u202e is important, as it also breaks the help command (refer image)

/urban: credit orig authors

Uni:
Also, watch the way you link it. Without crediting the original authors, you may be violating their license terms for reuse without sharing alike.

Support for StackExchange

Hi there, congrats for the cool project! ๐Ÿ˜‰

Is there any plan for supporting StackExchange-based chatrooms? I did a couple of tests and it looks doable: although I could not make the bot successfully login, it intercepts messages and parses them accordingly, so it seems we are almost there. ๐Ÿ˜‰

Just a quick info: maybe the fkey regex should be redone as the format looks quite different in SE sites (as it incorporates arbitrary length and hyphens). An alternative solution is to rely on jsoup for getting data from HTML sources.

Keep up the good work! ๐Ÿฐ

All the best,

Paulo

Exception thrown when "define" command is invoked

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 50; White spaces are required between publicId and systemId.
        at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
        at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1471)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.scanExternalID(XMLScanner.java:1071)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.scanDoctypeDecl(XMLDocumentScannerImpl.java:645)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:908)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541)
        at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
        at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
        at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
        at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
        at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:122)
        at oakbot.util.Leaf.parse(Leaf.java:95)
        at oakbot.command.define.DefineCommand.onMessage(DefineCommand.java:80)
        at oakbot.listener.CommandListener.onMessage(CommandListener.java:91)
        at oakbot.bot.Bot.handleListeners(Bot.java:538)
        at oakbot.bot.Bot.handleMessage(Bot.java:311)
        at oakbot.bot.Bot.lambda$connect$0(Bot.java:184)
        at java.base/java.lang.Thread.run(Thread.java:832)

Formatting issue with split messages

When a long message is formatted in italics or bold, and the message is split to adhere to SO Chat's length limitations, the formatting gets broken. The splitting code should add formatting syntax onto the beginning/end of each split message in order to preserve the formatting. Instead, you just see asterisks at the beginning of the first message and at the end of the last message.

Transcript link: https://chat.stackoverflow.com/transcript/message/43331588#43331588

/javadoc - handle tables

/javadoc SimpleDateFormat 5

The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 Y Week year Year 2009; 09 M Month in year (context sensitive) Month July; Jul; 07 L Month in year (standalone form) Month July; Jul; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d ...
Day in month Number 10 F Day of week in month Number 2 E Day name in week Text Tuesday; Tue u Day number of week (1 = Monday, ..., 7 = Sunday) Number 1 a Am/pm marker Text PM H Hour in day (0-23) Number 0 k Hour in day (1-24) Number 24 K Hour in am/pm (0-11) Number 0 h Hour in am/pm (1-12) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time; PST; ...
GMT-08:00 Z Time zone RFC 822 time zone -0800 X Time zone ISO 8601 time zone -08; -0800; -08:00 Pattern letters are usually repeated, as their number determines the exact presentation: Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated form is used if available. For parsing, both forms are accepted, independent of the number of pattern letters. (5/27)

Optional mention parameter for /javadoc

Sometimes I use the javadoc command to answer some other users question and I get pinged and after that I have to write another message to make sure the other user understands that the javadoc was meant for him.
If there could be something like
/javadoc searchedDoc [['@']username] that could sort that out. Just a tiny change but would help a lot :)

Using Reflections in order to reduce code in main

Every command of the Bot is added manually in the main class.
This can also be done by adding an Annotation and annotating all Commands with that.
Using Reflections, it is possible to scan for Classes that are annotated with a specified annotation. Using Reflection, it is possible to create an instance from the Class object.

SSLHandshakeException

May 14, 2015 1:46:08 PM oakbot.chat.StackoverflowChat executeWithRetries
INFO: Sleeping for 10000 ms before resending the request...
May 14, 2015 1:47:21 PM oakbot.Main$1 uncaughtException
SEVERE: Uncaught exception thrown.
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at oakbot.chat.StackoverflowChat.executeWithRetries(StackoverflowChat.java:287)
at oakbot.chat.StackoverflowChat.executeWithRetries(StackoverflowChat.java:250)
at oakbot.chat.StackoverflowChat.executeWithRetriesJson(StackoverflowChat.java:225)
at oakbot.chat.StackoverflowChat.getMessages(StackoverflowChat.java:131)
at oakbot.chat.StackoverflowChat.getNewMessages(StackoverflowChat.java:168)
at oakbot.bot.Bot.connect(Bot.java:84)
at oakbot.Main.main(Main.java:121)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
... 23 more

Fix auto-loading of new Javadoc ZIPs

SEVERE: Uncaught exception thrown.
java.util.zip.ZipError: zip END header not found
at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
at com.sun.nio.zipfs.ZipFileSystem.findEND(ZipFileSystem.java:1021)
at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1030)
at com.sun.nio.zipfs.ZipFileSystem.(ZipFileSystem.java:130)
at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:139)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:390)
at oakbot.command.javadoc.LibraryZipFile.(LibraryZipFile.java:36)
at oakbot.command.javadoc.JavadocDao.addApi(JavadocDao.java:73)
at oakbot.command.javadoc.JavadocDao.access$200(JavadocDao.java:28)
at oakbot.command.javadoc.JavadocDao$WatchThread.add(JavadocDao.java:204)
at oakbot.command.javadoc.JavadocDao$WatchThread.run(JavadocDao.java:178)

Rolling zero n-sided dice

Rolling zero n-sided dice will cause the message to be a malformed reply similar to :123456789
example issue producing commands: /roll 0d6 or /roll 0d0

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.