-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
176 lines (118 loc) · 5.21 KB
/
main.py
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import socket
import osu_irc
import random
import requests
from datetime import datetime, timedelta
#############################################################################################
TARGET_CHANNEL = '#mp_XXXXXXX'
api_key = "YOUR_OSU_API"
NICK = 'YOUR_OSU_USERNAME'
OAUTH_TOKEN = 'YOUR iirc.ppy.sh KEY'
#############################################################################################
##### MAP #################################
start_date = "2016-01-01"
end_date = datetime.today().strftime("%Y-%m-%d")
def generate_random_date(start_date, end_date):
# Convert start_date and end_date strings to datetime objects
start_datetime = datetime.strptime(start_date, "%Y-%m-%d")
end_datetime = datetime.strptime(end_date, "%Y-%m-%d")
# Calculate the range of days between start_date and end_date
delta_days = (end_datetime - start_datetime).days
# Generate a random number of days within the range
random_days = random.randint(0, delta_days)
# Add the random number of days to start_date to get the random date
random_date = start_datetime + timedelta(days=random_days)
# Format the random date as a string in "YYYY-MM-DD" format
formatted_random_date = random_date.strftime("%Y-%m-%d")
return formatted_random_date
def get_random_standard_beatmap_url(api_key):
random_date = generate_random_date(start_date, end_date)
# Make a request to the osu! API to get a list of beatmaps in standard mode
api_url = f"https://osu.ppy.sh/api/get_beatmaps?since={random_date} 00:00:00&k={api_key}&m=0" # '0' corresponds to the osu! standard mode
response = requests.get(api_url)
try:
response.raise_for_status() # Check for errors in the HTTP response
data = response.json()
# Check if the API request was successful
if data and "error" not in data:
filtered_beatmaps = [beatmap for beatmap in data if int(beatmap.get("total_length")) < 120]
if len(filtered_beatmaps)==0:
return get_random_standard_beatmap_url(api_key)
# Select a random beatmap from the list
random_beatmap = random.choice(filtered_beatmaps)
# Extract beatmap ID and set ID
beatmap_id = random_beatmap["beatmap_id"]
set_id = random_beatmap["beatmapset_id"]
# Construct the beatmap URL
beatmap_url = f"https://osu.ppy.sh/beatmapsets/{set_id}#osu/{beatmap_id}"
max_combo = int(random_beatmap["max_combo"])
return [beatmap_url, max_combo, beatmap_id]
else:
print(f"Error: {data.get('error')}")
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
##### GAMES ############################
acc = [50, 60, 70, 75, 80, 85, 90, 95]
combo_type = ['max combo', 'ending combo']
score = [100, 200, 300, 400, 500]
mods = ["+EZ", "+HD", "+HR", "+HDHR", "+FL", "+EZHD", "+EZFL"]
modsMSG = ["ez", "hd", "hr", "hd hr", "fl", "ez hd", "ez fl"]
other = ['CTB lowest score', 'Highest 50s count', 'Highest 100s count']
##### REQUIREMENTS ###################
def osu():
result = get_random_standard_beatmap_url(api_key)
map = result[0]
max_combo = result[1]
combo = random.randint(round(max_combo/10), round(max_combo/2))
miss = random.randint(round(max_combo/10), round(max_combo/3))
req = [acc, combo, score, other]
mod = random.choice(mods) if random.random() < 0.7 else "+NM"
if mod == "+NM":
modMSG = "nm"
else:
modMSG = modsMSG[mods.index(mod)]
game = random.choice(req)
if game == acc:
game = f'Closest acc to {random.choice(acc)}% wins'
elif game == combo:
game = f'Closest {random.choice(combo_type)} to {combo} wins'
elif game == miss:
game = f'Closest misscount to {miss} wins'
elif game == score:
game = f'Closest score to {random.choice(score)}k wins'
elif game == other:
game = f'{random.choice(other)} wins'
#print("")
#start = f'{map}\n**{mod}**\n{game}'
#print(start)
#pyperclip.copy(start)
#print("")
return [map, mod, game, result[2], modMSG]
#############################################################################################
def send(texte):
# Connect to osu! IRC server
server = 'irc.ppy.sh'
port = 6667
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
# Log in with osu! username and oauth token
irc.send(bytes(f'PASS {OAUTH_TOKEN}\r\n', 'UTF-8'))
irc.send(bytes(f'NICK {NICK}\r\n', 'UTF-8'))
# Join the target channel
irc.send(bytes(f'JOIN {TARGET_CHANNEL}\r\n', 'UTF-8'))
irc.send(bytes(f'PRIVMSG {TARGET_CHANNEL} :{texte}\r\n', 'UTF-8'))
# Close the connection
irc.close()
class MyBot(osu_irc.Client):
async def onReady(self):
await self.joinChannel(TARGET_CHANNEL)
async def onMessage(self, message):
msg = str(message)
if msg in ["!game","!g"]:
game = osu()
send(f'!mp map {game[3]}')
send(f'!mp mods {game[4]}')
send("WINNING CONDITION:")
send(game[2])
x = MyBot(token=OAUTH_TOKEN, nickname=NICK)
x.run()