-
Notifications
You must be signed in to change notification settings - Fork 23
Specify listeners in config file #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kevin-Mok
wants to merge
1
commit into
oldterns:master
Choose a base branch
from
Kevin-Mok:diff-listeners
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /target/ | ||
| /db/ | ||
| /cfg/vilebot*.conf | ||
| /db-backups/ | ||
| /db/ | ||
| /files/fonts/ | ||
| /log/ | ||
| /cfg/vilebot*.conf | ||
| /files/fonts/ | ||
| /target/ | ||
| utils/delete-backups.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| import java.io.FileInputStream; | ||||||
| import java.io.IOException; | ||||||
| import java.io.InputStream; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Enumeration; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.Map; | ||||||
|
|
@@ -61,6 +62,7 @@ | |||||
| import com.oldterns.vilebot.util.BaseNick; | ||||||
| import org.pircbotx.Configuration; | ||||||
| import org.pircbotx.MultiBotManager; | ||||||
| import org.pircbotx.hooks.Listener; | ||||||
| import org.pircbotx.hooks.ListenerAdapter; | ||||||
| import org.pircbotx.hooks.types.GenericMessageEvent; | ||||||
| import org.slf4j.Logger; | ||||||
|
|
@@ -79,6 +81,12 @@ public class Vilebot | |||||
|
|
||||||
| private static Map<String, String> cfg = getConfigMap(); | ||||||
|
|
||||||
| private static final String[] allListenerClasses = { "AnswerQuestion", "Ascii", "ChatLogger", "Church", "Countdown", | ||||||
| "Decide", "DownOrJustMe", "Excuses", "FakeNews", "Fortune", "GetInfoOn", "Help", "ImageToAscii", "Inspiration", | ||||||
| "Jaziz", "Jokes", "Kaomoji", "Karma", "KarmaRoll", "KarmaTransfer", "LastMessageSed", "LastSeen", "Markov", | ||||||
| "News", "Omgword", "Ops", "QuotesAndFacts", "RemindMe", "RockPaperScissors", "Summon", "Trivia", "Ttc", | ||||||
| "TwitterCorrection", "UrlTitleAnnouncer", "UrlTweetAnnouncer", "UserPing", "Userlists", "Weather" }; | ||||||
|
|
||||||
| private static JedisPool pool; | ||||||
|
|
||||||
| public static void main( String[] args ) | ||||||
|
|
@@ -113,20 +121,73 @@ public static void main( String[] args ) | |||||
| String ircServerAddress = cfg.get( "ircServerAddress" + i ); | ||||||
| int ircPort = Integer.parseInt( cfg.get( "ircPort" + i ) ); | ||||||
| String ircChannel = cfg.get( "ircChannel" + i ); | ||||||
| String listenerCsvString = cfg.get( "listeners" + i ); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This additional cfg entry should also be added in |
||||||
|
|
||||||
| BaseNick.addBotNick( ircNick ); | ||||||
|
|
||||||
| 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 DownOrJustMe() ).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 KarmaTransfer() ).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 Summon() ).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(); | ||||||
|
|
||||||
| botManager.addBot( botConfiguration ); | ||||||
| Configuration.Builder botCfg = new Configuration.Builder(); | ||||||
| botCfg.setName( ircNick ); | ||||||
| botCfg.setLogin( ircUser ); | ||||||
| botCfg.setRealName( ircRealName ); | ||||||
| botCfg.addServer( ircServerAddress, ircPort ); | ||||||
| botCfg.addAutoJoinChannel( ircChannel ); | ||||||
| botCfg.setAutoReconnect( true ); | ||||||
| botCfg.addListeners( convertListenerStrings( listenerCsvString ) ); | ||||||
| botManager.addBot( botCfg.buildConfiguration() ); | ||||||
| } | ||||||
|
|
||||||
| botManager.start(); | ||||||
| // Done | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Returns list of Listener object based on a CSV string of Listener class names. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @param listenerCsvString CSV list of listener class names. | ||||||
| * @return List of Listener objects. | ||||||
| **/ | ||||||
| private static ArrayList<Listener> convertListenerStrings( String listenerCsvString ) | ||||||
| { | ||||||
| ArrayList<Listener> listeners = new ArrayList<Listener>(); | ||||||
|
|
||||||
| // add admin listeners | ||||||
| listeners.add( new AdminManagement() ); | ||||||
| listeners.add( new AdminPing() ); | ||||||
| listeners.add( new Auth() ); | ||||||
| listeners.add( new GetLog() ); | ||||||
| listeners.add( new NickChange() ); | ||||||
| listeners.add( new Quit() ); | ||||||
|
|
||||||
| // add user listeners | ||||||
| String[] listenerStrings = | ||||||
| ( listenerCsvString.equals( "all" ) ) ? allListenerClasses : listenerCsvString.split( "," ); | ||||||
| for ( String listenerString : listenerStrings ) | ||||||
| { | ||||||
| listeners.add( createListenerFromString( listenerString ) ); | ||||||
| } | ||||||
|
|
||||||
| return listeners; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Returns Listener object based on class name. | ||||||
| * | ||||||
| * @param listenerString Name of class. | ||||||
| * @return Listener object of class name. | ||||||
| **/ | ||||||
| private static Listener createListenerFromString( String listenerString ) | ||||||
| { | ||||||
| final String className = "com.oldterns.vilebot.handlers.user." + listenerString; | ||||||
| try | ||||||
| { | ||||||
| return (Listener) Class.forName( className ).newInstance(); | ||||||
| } | ||||||
| catch ( InstantiationException | IllegalAccessException | ClassNotFoundException e ) | ||||||
| { | ||||||
| throw new IllegalStateException( e ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static Map<String, String> getConfigMap() | ||||||
| { | ||||||
| Map<String, String> cfg = new HashMap<>(); | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend this being a Class array instead of a String array, so that a missing class is a compile time error and to make it easier to rename classes when refactoring.