-
Notifications
You must be signed in to change notification settings - Fork 2
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
Plugin system restyling #15
Conversation
Ora un plugin NON ha più un tipo e ha un'unica coda di richieste. Ogni richiesta ha un tipo (in sostituzione del tipo di plugin). Ogni plugin lancia (al massimo) DUE thread (uno per tipo di richiesta). Cambiata l'interfaccia per rispondere alle richieste.
} else if (command.compareTo("help") == 0) {// E se non lo e' invia l'errore | ||
this.Help(new Request(channel, sender, rawParamsString)); | ||
} else { | ||
this.enqueueMessage(new Message(channel, "I don't know what I have to do at '" + command + "' request :(")); |
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.
Nel caso il comando non esista secondo me è più chiaro non scrivere nulla.
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.
!time
dopo un ipotetico secondo.....
ma è morto o il plugin non esiste?
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.
!help dà la risposta
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.
Non lo so.... Mi sembra brutto (e un po' maleducato)....
Ci ho dato uno sguardo molto veloce, una cosa che mi preme è che con @gianluca-nitti avevamo fatto in modo che il bot di hackernews andasse a intervalli regolari ma a partire da ore prestabilite, cosa che si è persa quando hai messo l'autotrancio. RisposteLa possibilità di far partire l'onPoll a intervalli regalari a partire da ore prestabilite è stata introdotta per tutti i plugin. DUE Thread: uno per il timer e uno per la blockingQueue che gestisce l'onCall. Avere un solo thread significherebbe accodare onCall e onPoll o spendere più tempo a runtime per capire quale eseguire, |
I thread vengono eseguiti PRIMA di settare loaded, quindi isLoaded() ritorna un valore dipendente dal tempo di scarto tra inizio esecuzione thread e fine caricamento plugin. In pratica un plugin funzionerà se e solo se ha fortuna!
Implementato un modo per definere la prima chiamata ad onPoll. Il codice precedentemente usato per il plugin HackerNews è tornato, e funge anche da esempio per gli altri!
@NeroReflex @doppioandante c'è qualche motivo particolare per cui non è ancora stato fatto il merge in master? |
Perché @NeroReflex aveva trovato un problema che adesso non ricordo. Un'altra cosa che non ho capito a che scopo sia stata messa è DelayedRequest. A parte questo non ho molto altro in contrario. In futuro mi piacerebbe che Request e Message venissero unificati perché non ha senso avere una distinzione semantica riguardo alla provenienza, è già implicita nella gerarchia di comunicazione bot/plugin. |
Matcher invokeMatcher = invokeRegex.matcher(message); | ||
if (invokeMatcher.matches()) { | ||
// Cerco di capire se mi e' stato dato un comando | ||
if ((message.charAt(0) == '!') && (message.length() > 1)) { |
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.
Può essere che arrivi un messaggio di lunghezza nulla?
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.
https://tools.ietf.org/html/rfc2812.html Sezione 2.3.1: "Empty messages are silently ignored"
// Ottieni il nome del comando | ||
String command = invokeMatcher.group(3).toLowerCase(); | ||
int firstSpacePos = message.indexOf(' '); | ||
firstSpacePos = (firstSpacePos <= -1)? message.length() : firstSpacePos; |
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.
Nit: di solito ci va lo spazio prima del ? del ternario, ma lascia pure così.
} else if (command.compareTo("info") == 0) {// E se non lo e' invia l'errore | ||
this.Info(new Request(channel, sender, rawParamsString)); | ||
} else { | ||
this.enqueueMessage(new Message(channel, "I don't know what I have to do at '" + command + "' request :(")); |
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.
La grammatica corretta sarebbe "to do with", e probabilmente quel "request" alla fine va tolto.
this.enqueueMessage(new Message(helpRequest.GetChannel(), "My source code <3 https://github.com/NeroReflex/Pizza")); | ||
} else { | ||
this.enqueueMessage(new Message(helpRequest.GetChannel(), "No info about that")); | ||
} |
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.
Penso che sarebbe più semplice far stampare semplicemente I'm blabla + url github (com'era prima forse?), è una complicazione inutile avere dei subcommands per info.
|
||
// Stampo la guida solo se ha senso (la stringa della guida NON E' vuota) | ||
if (!help.isEmpty()) | ||
this.enqueueMessage(new Message(helpRequest.GetChannel(), "!" + name + " " + help)); |
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.
Per ora OK, ma il si dovrà cambiare in modo che il messaggio con le informazioni di help arrivi in privato all'utente che l'ha richiesto, altrimenti intasa la chat (specie con molti plugin o con help lunghi).
if (!help.isEmpty()) | ||
this.enqueueMessage(new Message(helpRequest.GetChannel(), "!" + name + " " + help)); | ||
else | ||
this.enqueueMessage(new Message(helpRequest.GetChannel(), "Help is not bundled with the '" + name + "' plugin.")); |
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.
(There's) No help is provided by
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | ||
} | ||
|
||
}; |
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.
RequestRunner e TimerRunner si potevano fare come classi anonime ma va bene anche così.
} else { | ||
this.sendMessage(new Message(channel, user + "Please specify a channel")); | ||
this.sendMessage(new Message(channel, user + " Invalid channel name")); |
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.
Questo else avviene quando non si dà nessun canale, quindi ha più senso il messaggio che c'era prima.
// Chiave del canale? | ||
String key = ((args.size() > 1) && (args.get(1).length() > 0))? args.get(0) : ""; | ||
|
||
this.joinChannel(newChannel, key); | ||
this.sendMessage(new Message(channel, user + " I have joined " + newChannel)); | ||
this.sendMessage(new Message(channel, user + " I have joined the " + newChannel + " channel")); |
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.
Il messaggio di prima era meno verboso e si capisce ugualmente per via del # prima del nome del canale.
Cambiamenti STRUTTURALI:
!convert hex2bin 1aff5