Skip to content
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

Merged
merged 9 commits into from
Sep 21, 2016
Merged

Plugin system restyling #15

merged 9 commits into from
Sep 21, 2016

Conversation

NeroReflex
Copy link
Owner

Cambiamenti STRUTTURALI:

  • i plugin tornano a NON avere tipo, quindi un plugin unisce entrambe le tipologie.
  • il parsing del messaggio va fatto a mano (anche se il vecchio parsing rimane disponibile per retro-compatibilità e perché può far comodo ai neofiti)
  • ogni plugin lancia ben DUE Threads (per evitare che i due meccanismi di plugin si limitino fra loro)
  • le funzioni si lanciano così:
    !convert hex2bin 1aff5
  • una facile ed intuitiva guida si invoca così: !help
  • la guida di uno specifico plugin si invoca così: !help convert
  • maggiore velocità a runtime, soprattutto nel main thread (parte critica in Pizza)

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 :("));
Copy link
Collaborator

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.

Copy link
Owner Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

!help dà la risposta

Copy link
Owner Author

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)....

@doppioandante
Copy link
Collaborator

doppioandante commented Sep 13, 2016

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.
Non ho ancora guardato cosa intendi per 'ogni plugin lancia ben DUE Threads' ma a sentirla così non sembra una grande cosa, guarderò meglio se avrò tempo.

Risposte

La 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,
ma come è ora è più leggibile.

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!
@gianluca-nitti
Copy link
Collaborator

@NeroReflex @doppioandante c'è qualche motivo particolare per cui non è ancora stato fatto il merge in master?

@doppioandante
Copy link
Collaborator

Perché @NeroReflex aveva trovato un problema che adesso non ricordo.
A me sinceramente non piace il discorso dei due thread, dovrebbero essercene due solo se il plugin richiede l'attivazione periodica.
E comunque ancora non mi convince del tutto che ci sia questo kitchen sink dentro il plugin, preferivo una soluzione come quella dell'autotrancio che aggiunge la funzionalità del polling estendendo la classe Trancio: prima l'architettura del tutto rendeva le due cose esclusive, ora invece si può benissimo implementare così.

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)) {
Copy link
Collaborator

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?

Copy link
Owner Author

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;
Copy link
Collaborator

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 :("));
Copy link
Collaborator

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"));
}
Copy link
Collaborator

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));
Copy link
Collaborator

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."));
Copy link
Collaborator

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.
}

};
Copy link
Collaborator

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"));
Copy link
Collaborator

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"));
Copy link
Collaborator

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.

@NeroReflex NeroReflex merged commit 999235a into master Sep 21, 2016
@NeroReflex NeroReflex deleted the PluginSystem-restyling branch September 21, 2016 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants