-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleWebCommand.cs
More file actions
80 lines (74 loc) · 2.9 KB
/
SimpleWebCommand.cs
File metadata and controls
80 lines (74 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Cysharp.Threading.Tasks;
using OpenMod.Unturned.Plugins;
using OpenMod.API.Plugins;
using System.Threading.Tasks;
using SDG.Unturned;
using OpenMod.Core.Helpers;
[assembly: PluginMetadata("SS.SimpleWebCommand", DisplayName = "SimpleWebCommand")]
namespace SimpleWebCommand
{
public class SimpleWebCommand : OpenModUnturnedPlugin
{
private readonly IConfiguration ro_Configuration;
private readonly System.Random ro_Random = new System.Random();
private readonly ILogger<SimpleWebCommand> ro_Logger;
public SimpleWebCommand(
IConfiguration configuration,
ILogger<SimpleWebCommand> logger,
IServiceProvider serviceProvider) : base(serviceProvider)
{
ro_Configuration = configuration;
ro_Logger = logger;
}
protected override async UniTask OnLoadAsync()
{
ro_Logger.LogInformation("Plugin loaded correctly!");
ro_Logger.LogInformation("If you have any error you can contact the owner in discord: Senior S#9583");
string z = ro_Configuration.GetSection("plugin_configuration:url_with_interval").Get<string>();
if (z == "true")
{
var interval = ro_Configuration.GetSection("plugin_configuration:interval").Get<int>();
AsyncHelper.Schedule("Interval Url", () => IntervalUrl(this, interval));
}
}
public async Task IntervalUrl(IOpenModPlugin myPlugin, int interval)
{
while (myPlugin.IsComponentAlive)
{
await Task.Delay(TimeSpan.FromSeconds(interval));
await UniTask.SwitchToMainThread();
var z = ro_Configuration.GetSection("plugin_configuration:interval_urls").Get<string>().Split(',');
int random = ro_Random.Next(z.Length - 1);
if (random == 0 || random == 1)
{
var url = z[0];
var description = z[1];
SendUrl(url, description);
}
if (random % 2 == 0)
{
var url = z[random];
var description = z[random + 1];
SendUrl(url, description);
}
else
{
var url = z[random - 1];
var description = z[random];
SendUrl(url, description);
}
}
}
private void SendUrl(string url, string description)
{
foreach (var client in Provider.clients) client.player.sendBrowserRequest(description, url);
}
protected override async UniTask OnUnloadAsync()
{
ro_Logger.LogInformation("Plugin unloaded correctly!");
}
}
}