mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Add the Time::FromNow helper function.
This commit is contained in:
parent
5e1310188b
commit
d346d6783b
@ -63,11 +63,22 @@ namespace Time
|
||||
{
|
||||
/** Converts a UNIX timestamp to a time string.
|
||||
*
|
||||
* e.g.
|
||||
* @param ts The timestamp to convert to a string.
|
||||
* @param format A snprintf format string to output the timestamp in.
|
||||
* @param utc If the timestamp is a UTC timestamp then true or false if the
|
||||
* timestamp is a local timestamp.
|
||||
*/
|
||||
CoreExport std::string ToString(time_t ts, const char* format = nullptr, bool utc = false);
|
||||
|
||||
/** Converts a duration from now to a time string.
|
||||
*
|
||||
* @param duration The duration from now to convert to a string.
|
||||
* @param format A snprintf format string to output the timestamp in.
|
||||
* @param utc If the timestamp is a UTC timestamp then true or false if the
|
||||
* timestamp is a local timestamp.
|
||||
*/
|
||||
inline std::string FromNow(unsigned long duration, const char* format = nullptr, bool utc = false)
|
||||
{
|
||||
return ToString(ServerInstance->Time() + duration, format, utc);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ CmdResult CommandEline::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed E-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, target, Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -90,7 +90,7 @@ CmdResult CommandGline::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed G-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, target, Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
|
||||
ServerInstance->XLines->ApplyLines();
|
||||
|
@ -90,7 +90,7 @@ CmdResult CommandKline::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed K-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, target, Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
|
||||
ServerInstance->XLines->ApplyLines();
|
||||
|
@ -72,7 +72,7 @@ CmdResult CommandQline::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed Q-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, parameters[0], Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
ServerInstance->XLines->ApplyLines();
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ CmdResult CommandZline::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed Z-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, ipaddr, Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
ServerInstance->XLines->ApplyLines();
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed CBan on {}, expires in {} (on {}): {}",
|
||||
user->nick, parameters[0], Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), reason);
|
||||
Time::FromNow(duration), reason);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -471,7 +471,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, MessageTarget& msgtarget, M
|
||||
auto* sh = new Shun(ServerInstance->Time(), f->duration, MODNAME "@" + ServerInstance->Config->ServerName, f->reason, user->GetAddress());
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was shunned for {} (expires on {}) because their message to {} matched {} ({})",
|
||||
user->nick, sh->Displayable(), Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
msgtarget.GetName(), f->freeform, f->reason);
|
||||
if (ServerInstance->XLines->AddLine(sh, nullptr))
|
||||
{
|
||||
@ -485,7 +485,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, MessageTarget& msgtarget, M
|
||||
auto* gl = new GLine(ServerInstance->Time(), f->duration, MODNAME "@" + ServerInstance->Config->ServerName, f->reason, "*", user->GetAddress());
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was G-lined for {} (expires on {}) because their message to {} matched {} ({})",
|
||||
user->nick, gl->Displayable(), Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
msgtarget.GetName(), f->freeform, f->reason);
|
||||
if (ServerInstance->XLines->AddLine(gl, nullptr))
|
||||
{
|
||||
@ -499,7 +499,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, MessageTarget& msgtarget, M
|
||||
auto* zl = new ZLine(ServerInstance->Time(), f->duration, MODNAME "@" + ServerInstance->Config->ServerName, f->reason, user->GetAddress());
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was Z-lined for {} (expires on {}) because their message to {} matched {} ({})",
|
||||
user->nick, zl->Displayable(), Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
msgtarget.GetName(), f->freeform, f->reason);
|
||||
if (ServerInstance->XLines->AddLine(zl, nullptr))
|
||||
{
|
||||
@ -577,7 +577,7 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params&
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was G-lined for {} (expires on {}) because their {} message matched {} ({})",
|
||||
user->nick, gl->Displayable(),
|
||||
Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
command, f->freeform, f->reason);
|
||||
|
||||
if (ServerInstance->XLines->AddLine(gl, nullptr))
|
||||
@ -593,7 +593,7 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params&
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was Z-lined for {} (expires on {}) because their {} message matched {} ({})",
|
||||
user->nick, zl->Displayable(),
|
||||
Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
command, f->freeform, f->reason);
|
||||
|
||||
if (ServerInstance->XLines->AddLine(zl, nullptr))
|
||||
@ -610,7 +610,7 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params&
|
||||
ServerInstance->SNO.WriteGlobalSno('f', "{} ({}) was shunned for {} (expires on {}) because their {} message matched {} ({})",
|
||||
user->nick, sh->Displayable(),
|
||||
Duration::ToString(f->duration),
|
||||
Time::ToString(ServerInstance->Time() + f->duration),
|
||||
Time::FromNow(f->duration),
|
||||
command, f->freeform, f->reason);
|
||||
|
||||
if (ServerInstance->XLines->AddLine(sh, nullptr))
|
||||
|
@ -182,7 +182,7 @@ public:
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed R-line on {}, expires in {} (on {}): {}",
|
||||
user->nick, parameters[0], Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), parameters[2]);
|
||||
Time::FromNow(duration), parameters[2]);
|
||||
}
|
||||
|
||||
ServerInstance->XLines->ApplyLines();
|
||||
|
@ -129,7 +129,7 @@ public:
|
||||
{
|
||||
ServerInstance->SNO.WriteToSnoMask('x', "{} added a timed SHUN on {}, expires in {} (on {}): {}",
|
||||
user->nick, target, Duration::ToString(duration),
|
||||
Time::ToString(ServerInstance->Time() + duration), expr);
|
||||
Time::FromNow(duration), expr);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user