Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions vilebot/src/main/java/com/oldterns/vilebot/Vilebot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,56 @@
*/
package com.oldterns.vilebot;

import com.oldterns.vilebot.handlers.admin.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import com.oldterns.vilebot.handlers.admin.AdminManagement;
import com.oldterns.vilebot.handlers.admin.AdminPing;
import com.oldterns.vilebot.handlers.admin.Auth;
import com.oldterns.vilebot.handlers.admin.GetLog;
import com.oldterns.vilebot.handlers.admin.NickChange;
import com.oldterns.vilebot.handlers.admin.Quit;
import com.oldterns.vilebot.handlers.user.AnswerQuestion;
import com.oldterns.vilebot.handlers.user.Ascii;
import com.oldterns.vilebot.handlers.user.ChatLogger;
import com.oldterns.vilebot.handlers.user.Church;
import com.oldterns.vilebot.handlers.user.Countdown;
import com.oldterns.vilebot.handlers.user.Decide;
import com.oldterns.vilebot.handlers.user.Excuses;
import com.oldterns.vilebot.handlers.user.FakeNews;
import com.oldterns.vilebot.handlers.user.Fortune;
import com.oldterns.vilebot.handlers.user.GetInfoOn;
import com.oldterns.vilebot.handlers.user.Help;
import com.oldterns.vilebot.handlers.user.ImageToAscii;
import com.oldterns.vilebot.handlers.user.Inspiration;
import com.oldterns.vilebot.handlers.user.Jaziz;
import com.oldterns.vilebot.handlers.user.Jokes;
import com.oldterns.vilebot.handlers.user.Kaomoji;
import com.oldterns.vilebot.handlers.user.Karma;
import com.oldterns.vilebot.handlers.user.KarmaRoll;
import com.oldterns.vilebot.handlers.user.LastMessageSed;
import com.oldterns.vilebot.handlers.user.LastSeen;
import com.oldterns.vilebot.handlers.user.Markov;
import com.oldterns.vilebot.handlers.user.News;
import com.oldterns.vilebot.handlers.user.Omgword;
import com.oldterns.vilebot.handlers.user.Ops;
import com.oldterns.vilebot.handlers.user.*;
import com.oldterns.vilebot.handlers.user.QuotesAndFacts;
import com.oldterns.vilebot.handlers.user.Reddit;
import com.oldterns.vilebot.handlers.user.RemindMe;
import com.oldterns.vilebot.handlers.user.RockPaperScissors;
import com.oldterns.vilebot.handlers.user.Trivia;
import com.oldterns.vilebot.handlers.user.Ttc;
import com.oldterns.vilebot.handlers.user.TwitterCorrection;
import com.oldterns.vilebot.handlers.user.UrlTitleAnnouncer;
import com.oldterns.vilebot.handlers.user.UrlTweetAnnouncer;
import com.oldterns.vilebot.handlers.user.UserPing;
import com.oldterns.vilebot.handlers.user.Userlists;
import com.oldterns.vilebot.handlers.user.Weather;
import com.oldterns.vilebot.util.BaseNick;
import org.pircbotx.Configuration;
import org.pircbotx.MultiBotManager;
Expand All @@ -21,14 +67,6 @@
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Vilebot
extends ListenerAdapter
{
Expand Down Expand Up @@ -78,7 +116,7 @@ public static void main( String[] args )

Configuration botConfiguration =
new Configuration.Builder().setName( ircNick ).setLogin( ircUser ).setRealName( ircRealName ).addServer( ircServerAddress,
ircPort ).addAutoJoinChannel( ircChannel ).setAutoReconnect( true ).addListener( new Vilebot() ).addListener( new AdminManagement() ).addListener( new AdminPing() ).addListener( new Auth() ).addListener( new GetLog() ).addListener( new com.oldterns.vilebot.handlers.admin.Help() ).addListener( new NickChange() ).addListener( new com.oldterns.vilebot.handlers.admin.Ops() ).addListener( new Quit() ).addListener( new AnswerQuestion() ).addListener( new Ascii() ).addListener( new ChatLogger() ).addListener( new Church() ).addListener( new Countdown() ).addListener( new Decide() ).addListener( new Excuses() ).addListener( new FakeNews() ).addListener( new Fortune() ).addListener( new GetInfoOn() ).addListener( new Help() ).addListener( new ImageToAscii() ).addListener( new Inspiration() ).addListener( new Jaziz() ).addListener( new Jokes() ).addListener( new Kaomoji() ).addListener( new Karma() ).addListener( new KarmaRoll() ).addListener( new LastMessageSed() ).addListener( new LastSeen() ).addListener( new Markov() ).addListener( new News() ).addListener( new Omgword() ).addListener( new Ops() ).addListener( new QuotesAndFacts() ).addListener( new RemindMe() ).addListener( new RockPaperScissors() ).addListener( new Trivia() ).addListener( new Ttc() ).addListener( new TwitterCorrection() ).addListener( new UrlTitleAnnouncer() ).addListener( new UrlTweetAnnouncer() ).addListener( new Userlists() ).addListener( new UserPing() ).addListener( new Weather() ).buildConfiguration();
ircPort ).addAutoJoinChannel( ircChannel ).setAutoReconnect( true ).addListener( new Vilebot() ).addListener( new AdminManagement() ).addListener( new AdminPing() ).addListener( new Auth() ).addListener( new GetLog() ).addListener( new com.oldterns.vilebot.handlers.admin.Help() ).addListener( new NickChange() ).addListener( new com.oldterns.vilebot.handlers.admin.Ops() ).addListener( new Quit() ).addListener( new AnswerQuestion() ).addListener( new Ascii() ).addListener( new ChatLogger() ).addListener( new Church() ).addListener( new Countdown() ).addListener( new Decide() ).addListener( new Excuses() ).addListener( new FakeNews() ).addListener( new Fortune() ).addListener( new GetInfoOn() ).addListener( new Help() ).addListener( new ImageToAscii() ).addListener( new Inspiration() ).addListener( new Jaziz() ).addListener( new Jokes() ).addListener( new Kaomoji() ).addListener( new Karma() ).addListener( new KarmaRoll() ).addListener( new LastMessageSed() ).addListener( new LastSeen() ).addListener( new Markov() ).addListener( new News() ).addListener( new Omgword() ).addListener( new Ops() ).addListener( new QuotesAndFacts() ).addListener( new Reddit() ).addListener( new RemindMe() ).addListener( new RockPaperScissors() ).addListener( new Trivia() ).addListener( new Ttc() ).addListener( new TwitterCorrection() ).addListener( new UrlTitleAnnouncer() ).addListener( new UrlTweetAnnouncer() ).addListener( new Userlists() ).addListener( new UserPing() ).addListener( new Weather() ).buildConfiguration();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y'all, what is this line? Ends on column 1645?? At the very least break it up a little:

            Configuration botConfiguration =
                new Configuration.Builder()
                    .setName( ircNick )
                    .setLogin( ircUser )
                    .setRealName( ircRealName )
                    .addServer( ircServerAddress, ircPort )
                    .addAutoJoinChannel( ircChannel )
                    .setAutoReconnect( true )
                    .addListener( new Vilebot() )
                    .addListener( new AdminManagement() )
                    .addListener( new AdminPing() )
                    .addListener( new Auth() )
                    .addListener( new GetLog() )
                    .addListener( new com.oldterns.vilebot.handlers.admin.Help() )
                    .addListener( new NickChange() )
                    .addListener( new com.oldterns.vilebot.handlers.admin.Ops() )
                    .addListener( new Quit() )
                    .addListener( new AnswerQuestion() )
                    .addListener( new Ascii() )
                    .addListener( new ChatLogger() )
                    .addListener( new Church() )
                    .addListener( new Countdown() )
                    .addListener( new Decide() )
                    .addListener( new Excuses() )
                    .addListener( new FakeNews() )
                    .addListener( new Fortune() )
                    .addListener( new GetInfoOn() )
                    .addListener( new Help() )
                    .addListener( new ImageToAscii() )
                    .addListener( new Inspiration() )
                    .addListener( new Jaziz() )
                    .addListener( new Jokes() )
                    .addListener( new Kaomoji() )
                    .addListener( new Karma() )
                    .addListener( new KarmaRoll() )
                    .addListener( new LastMessageSed() )
                    .addListener( new LastSeen() )
                    .addListener( new Markov() )
                    .addListener( new News() )
                    .addListener( new Omgword() )
                    .addListener( new Ops() )
                    .addListener( new QuotesAndFacts() )
                    .addListener( new Reddit() )
                    .addListener( new RemindMe() )
                    .addListener( new RockPaperScissors() )
                    .addListener( new Trivia() )
                    .addListener( new Ttc() )
                    .addListener( new TwitterCorrection() )
                    .addListener( new UrlTitleAnnouncer() )
                    .addListener( new UrlTweetAnnouncer() )
                    .addListener( new Userlists() )
                    .addListener( new UserPing() )
                    .addListener( new Weather() )
                    .buildConfiguration();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VIleBot1 formatter does that. However, this task should be done in a more generic way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was a running joke tbh, which is why I never bothered to reformat it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running jokes have no place in code, not even in joke code

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the formatter is busted. Alternatively,

Builder builder = new Configuration.Builder();
builder.setName( ircNick );
builder.setLogin( ircUser )
// [...]


botManager.addBot( botConfiguration );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/
package com.oldterns.vilebot.handlers.user;

import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.types.GenericMessageEvent;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.types.GenericMessageEvent;

public class Help
extends ListenerAdapter
{
Expand Down Expand Up @@ -108,6 +108,7 @@ private static String generateHelpMessage()
sb.append( " { !asciifonts }" );
sb.append( " { !news [<category>] }" );
sb.append( " { !fakenews [<category>] }" );
sb.append( " { !reddit [<subreddit>] } " );
sb.append( "\n" );
sb.append( " Userlists:" );
sb.append( " { !list <listname> }" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class QuotesAndFacts
// update cache when new quotes/facts added
private Map<String, Integer> dumpSize = new HashMap<>();

private static final String PASTEBIN_API_URL = Vilebot.getConfig().get("pastebinApiUrl");
private static final String PASTEBIN_API_URL = Vilebot.getConfig().get( "pastebinApiUrl" );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for fixing this formatting, never got around to doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mvn did it for me; if you run mvn clean install it will auto-format your code


@Override
public void onJoin( final JoinEvent event ) // announce fact or quote on join
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (C) 2019 Oldterns
*
* This file may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

package com.oldterns.vilebot.handlers.user;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.oldterns.vilebot.Vilebot;
import com.oldterns.vilebot.util.LimitCommand;
import com.oldterns.vilebot.util.NewsParser;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.pircbotx.hooks.types.GenericMessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Reddit
extends NewsParser
{
private static final Logger logger = LoggerFactory.getLogger( Reddit.class );

private static final Pattern REDDIT_PATTERN = Pattern.compile( "^!reddit(?: ([a-zA-Z]+)|)" );

private static final Pattern REDDIT_HELP_PATTERN = Pattern.compile( "^!reddit help" );

private final String HELP_MESSAGE = generateHelpMessage();

private final String HELP_COMMAND = "'!reddit help'";

public static LimitCommand limitCommand = new LimitCommand();

private static final String RESTRICTED_CHANNEL = Vilebot.getConfig().get( "ircChannel1" );

@Override
public void onGenericMessage( final GenericMessageEvent event )
{
String text = event.getMessage();
Matcher matcher = REDDIT_PATTERN.matcher( text );
Matcher helpMatcher = REDDIT_HELP_PATTERN.matcher( text );

if ( helpMatcher.matches() )
{
for ( String line : HELP_MESSAGE.split( "\n" ) )
{
event.respondPrivateMessage( line );
}
}
else if ( matcher.matches() )
{
Map<String, ImmutablePair<String, URL>> redditRSSMap = new HashMap<>();
String subreddit = matcher.group( 1 ) != null ? matcher.group( 1 ) : "";
try
{
redditRSSMap.put( subreddit,
new ImmutablePair<String, URL>( "Subredit", new URL( new StringBuilder(
"https://reddit.com/" ).append( subreddit.isEmpty() ? subreddit : "r/" + subreddit + "/" ).append( ".rss" ).toString() ) ) );
currentNews( event, matcher, redditRSSMap, subreddit, HELP_COMMAND, limitCommand, RESTRICTED_CHANNEL,
logger );
}
catch ( MalformedURLException e )
{
event.respond( subreddit + " is not a subreddit." );
}

}
}

@Override
protected String generateHelpMessage()
{
StringBuilder sb = new StringBuilder();

sb.append( "Reddit (example: !reddit toronto)\n" );

return sb.toString();
}
}
26 changes: 12 additions & 14 deletions vilebot/src/main/java/com/oldterns/vilebot/util/NewsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

package com.oldterns.vilebot.util;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
Expand All @@ -19,12 +25,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.regex.Matcher;

public abstract class NewsParser

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this class is used for something other than news parsing, maybe rename it to something more generic like FeedParser? Not a blocker, just a recommendation.

extends ListenerAdapter
{
Expand All @@ -33,9 +33,8 @@ public abstract class NewsParser
protected static final int NUM_HEADLINES = 3;

protected void currentNews( GenericMessageEvent event, Matcher matcher,
LinkedHashMap<String, ImmutablePair<String, URL>> newsFeedsByCategory,
String defaultCategory, String helpCommand, LimitCommand limitCommand,
String restrictedChannel, Logger logger )
Map<String, ImmutablePair<String, URL>> newsFeedsByCategory, String defaultCategory,
String helpCommand, LimitCommand limitCommand, String restrictedChannel, Logger logger )
{
String category = matcher.group( 1 ); // The news category

Expand All @@ -52,9 +51,8 @@ protected void currentNews( GenericMessageEvent event, Matcher matcher,
}
}

protected void newsLimit( GenericMessageEvent event,
LinkedHashMap<String, ImmutablePair<String, URL>> newsFeedsByCategory, String category,
Logger logger, LimitCommand limitCommand, String restrictedChannel )
protected void newsLimit( GenericMessageEvent event, Map<String, ImmutablePair<String, URL>> newsFeedsByCategory,
String category, Logger logger, LimitCommand limitCommand, String restrictedChannel )
{
if ( event instanceof MessageEvent
&& ( (MessageEvent) event ).getChannel().getName().equals( restrictedChannel ) )
Expand All @@ -76,8 +74,8 @@ protected void newsLimit( GenericMessageEvent event,
}

protected void printHeadlines( GenericMessageEvent event,
LinkedHashMap<String, ImmutablePair<String, URL>> newsFeedsByCategory,
String category, Logger logger )
Map<String, ImmutablePair<String, URL>> newsFeedsByCategory, String category,
Logger logger )
{
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
Expand Down