[mega-thread] Automator - A forum bot that responds to domain removal requests (and soon more)

I’m calling it automator, it fulfills its destiny by automatically answering all domain removal topics that it receives from start. It will also include keywords that can be searched to find domain-removal topics tagged by automator, it’s almost done :stuck_out_tongue:

The code below is what used to do everything.

const fs = require("fs");
const crypto = require("crypto");
const nodemailer = require("nodemailer");

const transport = nodemailer.createTransport({
	host: "smtp.zoho.eu",
	port: 465,
	secure: true,
	auth: {
		user: "redacted",
		pass: "redacted"
	}
});

const createMessage = from => `Hello ${from}!
Welcome (back?) to Glitch!
For domain removals please send an email to support@glitch.com so they can start processing your domain removal request.
I totally understand that this might be frustrating, but this is the fastest way to get your custom domain removed.
I hope your problem get solved quickly!

Thanks,
Automator.

> **Note**: This is an automated message.

-- ignore this --
keyword-tag-domain-removal`;

const sendMessage = (user, id, from) => console.log("sending", user, id, from) || transport.sendMail({
	from: "'Spam', spam3@ihacks.dev",
	to: user,
	inReplyTo: id,
	text: createMessage(from)
});

const containsDomainRemoval = t => {
	t = t.trim().toLowerCase();
	return t.includes("domain");
};

exports.register = function ()
{
	this.register_hook("mail", "mail");
	this.register_hook("rcpt", "mail");
	this.register_hook("rcpt_ok", "mail");
	this.register_hook("data", "mail");
	this.register_hook("data_post", "mail");
	this.loginfo("Hello world")
}

exports.mail = function (next, con)
{
	if (con.hook === "mail")
	{
		con.transaction.parse_body = true;
	}
	if (con.hook === "data_post")
	{
		const user = con.transaction.mail_from.user + "@" + con.transaction.mail_from.host;
		console.log(con.transaction.body.children[0].bodytext)
		let msg = con.transaction.body.children[0].bodytext.match(/(.|\n)*(?=---)/g);
		if (!msg) return next(OK);
		msg = msg[0];
		if (!msg) return next(OK);
		msg = msg.trim();
		if (msg.length > 2000) return next(OK);
		let id = con.transaction.header.headers["message-id"];
		let sub = con.transaction.header.headers["subject"];
		if (!id) return next(OK);
		if (!sub) return next(OK);
		if (!id[0]) return next(OK);
		if (!sub[0]) return next(OK);
		id = id[0].substring(1, id[0].length - 2);
		sub = sub[0].trim();
		let inReplyTo = con.transaction.header.headers["in-reply-to"];
		inReplyTo = inReplyTo[0].substring(1, inReplyTo[0].length - 2);
		let from = con.transaction.header.headers["from"];
		if (!from) return next(OK);
		from = from[0];
		if (from.includes(" via Glitch Support <glitch@discoursemail.com>\n")) from = from.substring(0, from.length - 48);
		console.log(user, inReplyTo, id);
		console.log(from);
		console.log(sub);
		console.log(msg);
		if (containsDomainRemoval(sub) || containsDomainRemoval(msg))
			sendMessage(user, id, from);
	}
	next(OK);
}

6 Likes

Btw, if this is not allowd I will take it down again.

1 Like

Omega fail on my side:

@EddiesTech

1 Like

(ignore this) domain not working test

Must have been all the testing.

Yeah :joy:


Hope we’ll see it in action tomorrow xd

This is a really cool - I was gonna do it with the API, but this is a great way to do it without a token! Can’t wait to see it in action. I wonder how long it will take from seeing a topic and then replying

This should be in #the-gallery, will Automator do it automatically? :joy:

Disclaimer: if you’re using a Gmail account for Nodemailer, you will have to use Gmail oAuth and simply “allowing less secure apps” for your Gmail account will not work. Pro: no need to enable less secure apps, better security, and no need to enter your password in the pass field (the oAuth token is enough). Cons: too complicated.

Instructions here: https://medium.com/@nickroach_50526/sending-emails-with-node-js-using-smtp-gmail-and-oauth2-316fe9c790a1

From a user concerned about other Gmail users, having struggled with Nodemailer in the past.

This seems great!!! I :heart: it!!

@ihack2712 how does it know if you want a domain removal.

actually the code runs on Haraka, which is a node.js mailing server, and a custom sendmail host (Zoho). Google (or gmail) is out of the picture :wink:

It seems Haraka wasn’t the best choice but I am looking into other free options as well.

I’ll be doing a remake of this using puppeteer, because I realize now that the Haraka mail server is over 9 years old, and hasn’t a had a commit in their repo in 5 years.

I’ll be posting along when I have other news :slight_smile:

Ok! Can’t wait to see it in action when it’s done! :heart:

Very confused as to how its gonna get the email of the person who posted for a domain removal request. Or does it email glitch?

I have another account setup @automator, which has maling list mode on. So it in theory should receive an email about everything.

Second I went on to my VPS and created a plugin for the mail server known as Haraka (don’t recommend it btw). And that receives emails, sometimes.

For some reason, it seems to be stuck in the past, because it keeps receiving old emails. Idk where they come from.

Third, I’m using nodemailer and a 3rd party email to send emails back to discourse.

1 Like

ahh i got u. btw delete email sonce processed I run into that a lot.if all doesn’t work, just store processed emails in a DB as you get em and cross check u haven’t seen it before

That’s not the problem, I have written a short script to test that theory but that doesn’t work, it seems to receive a lot of emails still, old connections are literally opened to send me old emails. I will use a similar method on the new system, but that won’t be using silly emails. xd

Status Update 1:

The bot can now log in to the account.

1 Like