3 var ChannelModule = require("./module");
4 var Flags = require("../flags");
6 function makeIPHash(ip) {
8 for(var i = 0 ; i < ip.length ; i++){
9 if(ip.charAt(i) != '.'){
10 numeric += ip.charAt(i);
13 numeric = parseInt(numeric);
14 return makeID((numeric * 13) % 1000000);
17 function makeID(id_number){
18 var id_string = "" + id_number;
19 var processed_string = "";
20 for(var i = 0 ; i < id_string.length ; i += 2){
21 var num = id_string.charAt(i)
22 if(i + 1 < id_string.length) num += id_string.charAt(i + 1);
23 num = parseInt(num) % 61;
24 processed_string += convertNumToIDChar("" + num);
26 return processed_string;
29 // Xaekai on Jan 14, 2019
30 function convertNumToIDChar(num){
31 const i = parseInt(num, 10);
33 case i > -1 && i < 26: return String.fromCharCode(i+97);
34 case i > 25 && i < 52: return String.fromCharCode(i+39);
35 case i > 51 && i < 61: return String.fromCharCode(i-3);
36 case i === 61: return '0';
38 console.log('notret');
41 function AnonymousPost(_channel) {
42 ChannelModule.apply(this, arguments);
45 AnonymousPost.prototype = Object.create(ChannelModule.prototype);
47 AnonymousPost.prototype.onUserPreJoin = function (user, data, cb) {
48 const opts = this.channel.modules.options;
49 var anonymousPosting = opts.get("allow_anon_chat");
50 if(anonymousPosting && user.isAnonymous()){
51 var hash = makeIPHash(user.realip);
52 var anon_name = "Anonymous-" + hash;
53 var duplicate_solution = 0;
54 var duplicate_found = false;
56 duplicate_found = false;
57 user.channel.users.forEach((user, i) => {
58 if (!duplicated_found && user.account.name == anon_name){
60 anon_name = "Anonymous-" + hash + duplicate_solution;
61 duplicate_found = true;
65 while(duplicated_found);
66 user.guestLogin(anon_name);
67 cb(null, ChannelModule.PASSTHROUGH);
70 cb(null, ChannelModule.PASSTHROUGH);
74 module.exports = AnonymousPost;
75 //# sourceMappingURL=anonymouspost.js.map