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

Added user cookie plugins #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
61 changes: 61 additions & 0 deletions cookie-user/cookie-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function randString(n) {
if(!n)
{
n = 5;
}

var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

for(var i=0; i < n; i++)
{
text += possible.charAt(Math.floor(Math.random() * possible.length));
}

return text;
}

// Cookies
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";

document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name, "", -1);
}

var cookie = readCookie('cookie_name');
console.log(cookie);
if (cookie == null) {
var value = randString(9);
createCookie('cookie_name', value, 30);
}


kiwi.plugin('ident', function(kiwi) {

kiwi.state.$on('network.new', function(event) {
event.network.username = cookie;

});

});

6 changes: 6 additions & 0 deletions cookie-user/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Simos
* admin@simosnap.org
* https://github.com/SimosNap

### Description
Set a random value saved in a cookie as kiwiirc username.
18 changes: 18 additions & 0 deletions nickserv/nickserv.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.kiwi-ns-error:before {
font-family:FontAwesome;
content: "\f071" ;
margin-right:5px;
}
.kiwi-ns-input {
border-top:1px solid rgba(0, 0, 0, 0.2) !important;
padding:10px !important;
}
.kiwi-ns-button {
font-size:1.2em;border-radius:0px;
}

.kiwi-ns-button:before {
font-family:FontAwesome;
content: "\f023" ;
margin-right:5px;
}
114 changes: 114 additions & 0 deletions nickserv/nickserv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Plugin Config #########################################################################

// NickServ Identify Regex
var IDString = "^Questo nick è registrato e protetto. Se questo è il tuo";
// NickServ Identify text
var IDText = "Il nick scelto risulta registrato, inserisci la password per autenticarti.";
// IDentify Button text
var IDButton = "IDENTIFICATI";
// Wrong password Regex
var WPString = "^Password errata";
// Wrong password text
var WPText = "Password errata!";
// Services enforce nick Regex
var ENString = "^Il tuo nick sarà cambiato in";
// Login success Regex
var LSString = "^Password accettata - adesso sei riconosciuto";
// Account confirmation request Regex
var ConfirmReqString = "^Il tuo indirizzo email non è stato confermato. Per confermarlo, segui le istruzioni contenute nella email che hai ricevuto quando ti sei registrato";
// Account confirmation text
var ConfirmReqText = "Inserisci il codice di conferma ricevuto per email per completare la registrazione dell\' account.";
// Invalid Confirmation code Regex
var InvalidConfirmString = "^Codice di attivazione non valido";
// Invalid Confirmation code text
var InvalidConfirmText = "Codice di attivazione non valido. Inserisci il codice di conferma ricevuto per email per completare la registrazione dell\' account.";
// A valid confirmation code has been entered
var ValidConfirmString = "^Il tuo indirizzo email per (.*) è stato confermato."

// Confirm Button text
var ConfirmButton = "CONFERMA REGISTRAZIONE";
// End Plugin Config ####################################################################

var IDRe = new RegExp(IDString ,"");
var WPRe = new RegExp(WPString ,"");
var ENRe = new RegExp(ENString ,"");
var LSRe = new RegExp(LSString ,"");
var ConfirmReqRe = new RegExp(ConfirmReqString ,"");
var InvalidConfirmRe = new RegExp(InvalidConfirmString ,"");
var ValidConfirmRe = new RegExp(ValidConfirmString ,"");

var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "/plugins/nickserv.css";
document.head.appendChild(link);

var nsdialog = kiwi.Vue.extend({

data: function data() {
return {
pwdInput: ''
}
},

methods: {
onIdentify: function () {
kiwi.state.$emit('input.raw', '/NS identify '+ this.pwdInput )
}
},

template: '<div class="kiwi-default-simple-nick input-text input-text--focus input-text--reveal-value" id="nickserv-form" title="NickServ" style="text-align:center;"><p class="kiwi-default-simple-error kiwi-ns-error" id="validate">' + IDText + '</p><input class="kiwi-ns-input" placeholder="Inserisci la password" type="password" v-model="pwdInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button class="u-button u-button-primary u-submit kiwi-default-simple-start kiwi-ns-button" v-on:click="onIdentify" >' + IDButton + '</button></div>',
});

var confirmdialog = kiwi.Vue.extend({

data: function data() {
return {
codeInput: ''
}
},

methods: {
onIdentify: function () {
kiwi.state.$emit('input.raw', '/NS confirm '+ this.codeInput )
}
},

template: '<div class="kiwi-default-simple-nick input-text input-text--focus input-text--reveal-value" id="nickserv-form" title="NickServ" style="text-align:center;"><p class="kiwi-default-simple-error kiwi-ns-error" id="validate">' + ConfirmReqText + '</p><input class="kiwi-ns-input" placeholder="Inserisci il codice di conferma" type="text" v-model="codeInput"><div class="input-text-underline"><div class="input-text-underline-active"></div></div><button class="u-button u-button-primary u-submit kiwi-default-simple-start kiwi-ns-button" v-on:click="onIdentify" >' + ConfirmButton + '</button></div>',
});

kiwi.plugin('nickserv', function(kiwi) {

kiwi.on('irc.notice', function(event) {
console.log(event);
if ((event.nick == 'NickServ') && (event.message.match(IDRe))) {
kiwi.state.$emit('mediaviewer.show', {component: nsdialog })
}
if ((event.nick == 'NickServ') && (event.message.match(WPRe))) {
var el = document.getElementById("validate")
el.innerHTML = WPText ;
}
if ((event.nick == 'NickServ') && (event.message.match(ConfirmReqRe))) {
kiwi.state.$emit('mediaviewer.show', {component: confirmdialog })
}

if ((event.nick == 'NickServ') && (event.message.match(InvalidConfirmRe))) {
var el = document.getElementById("validate")
el.innerHTML = InvalidConfirmText ;
}

if ((event.nick == 'NickServ') && (event.message.match(ENRe))) {
kiwi.state.$emit('mediaviewer.hide')
}

if ((event.nick == 'NickServ') && (event.message.match(LSRe))) {
kiwi.state.$emit('mediaviewer.hide')
}

if ((event.nick == 'NickServ') && (event.message.match(ValidConfirmRe))) {
kiwi.state.$emit('mediaviewer.hide')
}

});

});