Skip to content

Commit

Permalink
feat: expose native report message in config
Browse files Browse the repository at this point in the history
  • Loading branch information
warriordog committed Aug 22, 2024
1 parent d4b70aa commit ced3ce0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions ModShark/Reports/Reporter/NativeReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class NativeReporterConfig
{
public bool Enabled { get; set; } = true;
public bool UseApi { get; set; }

public string InstanceReportComment { get; set; } = "ModShark: instance matched one or more flagged patterns";
public string UserReportComment { get; set; } = "ModShark: user matched one or more flagged patterns";
public string NoteReportComment { get; set; } = "ModShark: note matched one or more flagged patterns";
}

public class NativeReporter(ILogger<NativeReporter> logger, NativeReporterConfig reporterConfig, SharkeyContext db, ISharkeyIdService sharkeyIdService, IUserService userService, ISharkeyHttpService http, ILinkService linkService) : INativeReporter
{
private const string InstanceReportComment = "ModShark: instance matched one or more flagged patterns";
private const string UserReportComment = "ModShark: user matched one or more flagged patterns";
private const string NoteReportComment = "ModShark: note matched one or more flagged patterns";

public async Task MakeReport(Report report, CancellationToken stoppingToken)
{
if (!reporterConfig.Enabled)
Expand Down Expand Up @@ -56,7 +56,7 @@ private async Task SaveUserReports(Report report, string reporterId, Cancellatio

foreach (var userReport in report.UserReports)
{
await MakeReport(userReport.User.Id, userReport.User.Host, reporterId, UserReportComment, report.ReportDate, stoppingToken);
await MakeReport(userReport.User.Id, userReport.User.Host, reporterId, reporterConfig.UserReportComment, report.ReportDate, stoppingToken);
}
}

Expand All @@ -77,7 +77,7 @@ private async Task SaveInstanceReports(Report report, string reporterId, Cancell
continue;
}

var comment = $"Instance: {linkService.GetLinkToInstance(instanceReport.Instance)}\n-----\n{InstanceReportComment}";
var comment = $"Instance: {linkService.GetLinkToInstance(instanceReport.Instance)}\n-----\n{reporterConfig.InstanceReportComment}";
await MakeReport(reportedId, instanceReport.Instance.Host, reporterId, comment, report.ReportDate, stoppingToken);
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ private async Task SaveNoteReports(Report report, string reporterId, Cancellatio

foreach (var noteReport in report.NoteReports)
{
var comment = $"Local Note: {linkService.GetLocalLinkToNote(noteReport.Note)}\n-----\n{NoteReportComment}";
var comment = $"Local Note: {linkService.GetLocalLinkToNote(noteReport.Note)}\n-----\n{reporterConfig.NoteReportComment}";

if (noteReport.IsLocal)
comment = $"Note: {linkService.GetLinkToNote(noteReport.Note)}\n" + comment;
Expand Down
5 changes: 4 additions & 1 deletion ModShark/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@

"Native": {
"Enabled": true,
"UseApi": false
"UseApi": false,
"InstanceReportComment": "ModShark: instance matched one or more flagged patterns",
"UserReportComment": "ModShark: user matched one or more flagged patterns",
"NoteReportComment": "ModShark: note matched one or more flagged patterns"
},

"Post": {
Expand Down

0 comments on commit ced3ce0

Please sign in to comment.