-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
142 lines (120 loc) · 5.15 KB
/
Program.cs
File metadata and controls
142 lines (120 loc) · 5.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var builder = WebApplication.CreateBuilder(args);
// Add CORS policy to allow all origins
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin() // Allows all origins
.AllowAnyMethod() // Allows all HTTP methods (GET, POST, etc.)
.AllowAnyHeader(); // Allows all headers
});
});
var app = builder.Build();
app.UseCors("AllowAll");
app.MapGet("/", () =>
{
var endpoints = new List<Endpoints>
{
new Endpoints {endpoint = "/", name = "Home", description = "Welcome to pointless API."},
new Endpoints {endpoint = "/weather", name = "Random Weather", description = "Get the current weather from a random city in the USA."},
new Endpoints {endpoint = "/magic8", name="Magic 8 Ball", description = "Get the answer to all your burning questions."},
new Endpoints {endpoint = "/talktothehand", name="Talk to the Hand (no)", description="There's always another way to say no."},
new Endpoints {endpoint = "/istiktokshutdown", name = "Is TikTok Shut Down", description = "The latest, up-to-date news on whether TikTok is shut down or not."},
new Endpoints {endpoint = "/scramble?word=", name = "Vowel Scrambler", description = "Substitute a taco emoji for all vowels in the word."},
new Endpoints {endpoint = "/istwitterfunctioningasintended", name = "Is Twitter Functioning as Intended", description = "Find out whether Twitter is working or not."},
new Endpoints {endpoint = "/twitter?username=", name="Twitter Redirect", description="Redirect to a twitter profile."},
new Endpoints {endpoint = "/movieclub", name = "Movie Club Endpoints", description = "Find all the #movieClub endpoints"},
new Endpoints {endpoint = "/alphabet", name = "Frontend Alphabet API", description = "Letters are hard. There's an API for that."},
new Endpoints {endpoint = "/todayisnot", name = "Today Is Not", description = "Find out what day it isn't"}
};
var about = new About().about;
return Results.Json(new { about = about, endpoints = endpoints });
});
app.MapMethods("/", new[] { "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD" }, (HttpContext context) =>
{
var method = context.Request.Method;
return Results.Json(new { message = $"Congratulations on your {method} request!"}, statusCode: 200);
});
app.MapGet("/scramble", (HttpContext context) =>
{
var query = context.Request.Query["word"];
string scrambled = new string(query.ToString().ToArray());
string newString = "";
List<char> repalceable = new List<char>{'a', 'e', 'i', 'o', 'u'};
foreach(char letter in scrambled) {
if (repalceable.Contains(letter)) {
newString += "🌮";
}
else {
newString += letter;
}
}
// string result = new string(newString.ToArray());
return Results.Json(new { message = newString });
});
app.MapGet("/magic8", () =>
{
string response = randomize.MagicEight.responses();
return Results.Json(new { message = response });
});
app.MapGet("/istiktokshutdown", () =>
{
return Results.Json(new { message = "I don't even know any more..." });
}
);
// app.MapPost("/ntl", static async () =>
// {
// string title = await Icecast.Icecast.NowPlaying();
// return Results.Json(new {title = title});
// }
// );
app.MapGet("/twitter", (HttpContext context) => {
string? username = context.Request.Query["username"];
return Results.Redirect($"https://twitter.com/{username}");
}
);
app.MapGet("/movieclub", ()=> {
string movies = "iqdit.cc/c7185b8";
string reviews = "iqdit.cc/fdce562";
string members = "iqdit.cc/e3f1a85";
return Results.Json(new {movies = movies, reviews = reviews, members = members});
}
);
app.MapGet("/talktothehand", () => {
string no = randomize.TalkToTheHand.responses();
return Results.Json(new {answer = no});
});
app.MapGet("istwitterfunctioningasintended", async () =>
{
HttpClient client = new HttpClient();
string url = "https://twitter.com";
HttpResponseMessage response = await client.GetAsync(url);
int statusCode = (int)response.StatusCode;
if (statusCode == 200)
{
return Results.Json(new { answer = "The status code is 200, but who knows." });
}
return Results.Json(new { answer = $"The status code is {statusCode}, ngmi." });
});
app.MapGet("/weather", async () =>
{
string forecast = await Weather.RunAsync();
return Results.Json(new { forecast = forecast });
}
);
app.MapGet("/elbowfetish", () =>
{
return Results.Redirect("https://twitter.com/LaFemmeFrank");
});
app.MapGet("/alphabet", () =>
{
return Results.Redirect("https://www.costcobros.com/PaaS/alphabet");
});
app.MapGet("/todayisnot", () =>
{
string today = randomize.DayItIsnt.response();
string response = "Today is not " + today;
return Results.Json(new {response = response});
});
app.MapFallback(() => Results.NotFound(new { Message = "What are you looking for?? Suggest new pointless endpoint ideas to: twitter.com/BenjaminMuses" }));
app.Run();