|
|
@@ -157,7 +157,7 @@ void ImageWriter::WriteText(pngwriter &writer, pngwriterfont &font, char fontSiz
|
|
|
int ImageWriter::WriteText(pngwriter &writer, pngwriterfont& font, char fontSize, const Anope::string &str, int lineIndex, const RGB &rgb)
|
|
|
{
|
|
|
const char lineHeight = fontSize +6,
|
|
|
- marginSize = 10;
|
|
|
+ marginSize = fontSize;
|
|
|
char *cstrFull = strdup(str.c_str());
|
|
|
int maxLen = GetTextLength(writer, font, fontSize, cstrFull, right -left -2*marginSize);
|
|
|
int written = 0;
|
|
|
@@ -216,6 +216,17 @@ public:
|
|
|
void OnEndBuffer() anope_override;
|
|
|
};
|
|
|
|
|
|
+class FileRemover: public Timer
|
|
|
+{
|
|
|
+ const std::string path;
|
|
|
+
|
|
|
+public:
|
|
|
+ FileRemover(const std::string &path);
|
|
|
+
|
|
|
+ void Tick(time_t t) anope_override;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
class CommandISCreate : public Command
|
|
|
{
|
|
|
ISCreate *creator;
|
|
|
@@ -258,11 +269,21 @@ class ISCreate : public Module
|
|
|
ISCreate::ISCreate(const Anope::string &modname, const Anope::string &creator): Module(modname, creator, VENDOR), commandiscreate(this)
|
|
|
{}
|
|
|
|
|
|
-InstaMessageBufferImpl::InstaMessageBufferImpl(ISCreate *m, User *user) :Timer(*instaServ, Config->GetModule("instaserv")->Get<time_t>("typingtimeout", "1m")), u(user), module(m)
|
|
|
+FileRemover::FileRemover(const std::string &_path): Timer(*instaServ, Config->GetModule("is_create")->Get<time_t>("expireafter", "30m")), path(_path)
|
|
|
+{}
|
|
|
+
|
|
|
+void FileRemover::Tick(time_t t)
|
|
|
+{
|
|
|
+ Log(LOG_DEBUG) << "InstaServ: removing " << path;
|
|
|
+ ::unlink(path.c_str());
|
|
|
+}
|
|
|
+
|
|
|
+InstaMessageBufferImpl::InstaMessageBufferImpl(ISCreate *m, User *user) :Timer(*instaServ, Config->GetModule("is_create")->Get<time_t>("typingtimeout", "5m")), u(user), module(m)
|
|
|
{}
|
|
|
|
|
|
void InstaMessageBufferImpl::Tick(time_t t)
|
|
|
{
|
|
|
+ u->SendMessage((*instaServ)->GetBotInfo(), "Error: timeout reached.");
|
|
|
(*instaServ)->OnExpire(u);
|
|
|
}
|
|
|
|
|
|
@@ -313,10 +334,11 @@ void InstaMessageBufferImpl::OnEndBuffer()
|
|
|
ImageWriter builder;
|
|
|
const Configuration::Block* config = Config->GetModule("is_create");
|
|
|
const Anope::string filename = hash(u->nick) +".png";
|
|
|
+ const Anope::string path = config->Get<Anope::string>("output", "") +"/" +filename;
|
|
|
|
|
|
builder.SetBackground(config->Get<Anope::string>("background", ""))
|
|
|
.SetText(lines)
|
|
|
- .SetOutputPath(config->Get<Anope::string>("output", "") +"/" +filename)
|
|
|
+ .SetOutputPath(path)
|
|
|
.SetQuotePosition(
|
|
|
config->Get<unsigned>("quoteTop", "0"),
|
|
|
config->Get<unsigned>("quoteLeft", "0"),
|
|
|
@@ -329,6 +351,8 @@ void InstaMessageBufferImpl::OnEndBuffer()
|
|
|
builder.Build(u);
|
|
|
u->SendMessage((*instaServ)->GetBotInfo(), "Image exported as " +config->Get<Anope::string>("httpRoot", "") +filename);
|
|
|
(*instaServ)->OnExpire(u);
|
|
|
+ TimerManager::DelTimer(this);
|
|
|
+ new FileRemover(path.c_str());
|
|
|
}
|
|
|
|
|
|
MODULE_INIT(ISCreate)
|