| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "module.h"
- #include "instaserv.h"
- static ServiceReference<InstaServCore> instaServ("InstaServService", "InstaServ");
- class ISCreate;
- class InstaMessageBufferImpl: public InstaMessageBuffer, public Timer
- {
- std::vector<Anope::string> lines;
- User *u;
- ISCreate *module;
- public:
- InstaMessageBufferImpl(ISCreate *m, User *user);
- void Tick(time_t t) anope_override;
- void Add(Anope::string &msg) anope_override;
- size_t LineCount() const anope_override;
- void OnEndBuffer() anope_override;
- };
- class CommandISCreate : public Command
- {
- ISCreate *creator;
- public:
- CommandISCreate(ISCreate *c, const Anope::string &sname = "instaserv/create") : Command((Module*) c, sname, 0, 0), creator(c)
- {
- this->SetDesc(_("Create a new quote"));
- this->SetSyntax("");
- }
- void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
- {
- if (!source.GetUser())
- return;
- source.Reply("Type in your quote, end with a line only containing `EOF'");
- instaServ->SetBuffer(source.GetUser(), new InstaMessageBufferImpl(creator, source.GetUser()));
- }
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
- {
- this->SendSyntax(source);
- source.Reply(_(" \n"
- "Create a new quote image"));
- return true;
- }
- };
- class ISCreate : public Module
- {
- CommandISCreate commandiscreate;
- public:
- ISCreate(const Anope::string &modname, const Anope::string &creator);
- size_t GetMaxLines()
- {
- return 5;
- }
- };
- 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)
- {}
- void InstaMessageBufferImpl::Tick(time_t t)
- {
- (*instaServ)->OnExpire(u);
- }
- void InstaMessageBufferImpl::Add(Anope::string &msg)
- {
- if (LineCount() < module->GetMaxLines())
- lines.push_back(msg);
- else
- {
- std::stringstream ss;
- ss << "Cannot paste more than " << module->GetMaxLines() << " lines";
- u->SendMessage((*instaServ)->GetBotInfo(), ss.str());
- }
- }
- size_t InstaMessageBufferImpl::LineCount() const
- {
- return lines.size();
- }
- void InstaMessageBufferImpl::OnEndBuffer()
- {
- Log(LOG_DEBUG) << "::: received END";
- (*instaServ)->OnExpire(u);
- }
- MODULE_INIT(ISCreate)
|