init from 2021
This commit is contained in:
commit
c46421267a
|
@ -0,0 +1,11 @@
|
|||
# Contains bot token
|
||||
data.json
|
||||
|
||||
# You not supposted to see this
|
||||
horny_poster.py
|
||||
horny_data.json
|
||||
|
||||
# shit
|
||||
.idea
|
||||
.vscode
|
||||
aprint/__pycache__
|
|
@ -0,0 +1,8 @@
|
|||
### My personal discord-vk bot, that u used approximatley in 2019-2021
|
||||
I don't even think it's gonna work now, in 2024, but i still decided to publish it
|
||||
|
||||
**main.py** contains script, that runs discord and vk bot in parallel with mute and ban checker threads. There are mostly features for discord, like activity tracking, count channel tracking, and special command that enables only for a limited time (new year event), as well as moderation functionality, such as muts, bans, logs of deleted messages.
|
||||
|
||||
**midnigth.py** launches with cron one minute before new day. It downloads the picture of the day from my VK album, chooses *bad* person of the day (only for discord), and then sends the message to the chosen Discord channel and VK conversation.
|
||||
|
||||
Will i revive it? No.
|
|
@ -0,0 +1 @@
|
|||
from .aprint import info, notice, warn, error, debug, none
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
Advanced Print Logging by thehatkid
|
||||
GitHub: https://github.com/thehatkid
|
||||
"""
|
||||
|
||||
from colorama import init, Fore
|
||||
import datetime
|
||||
|
||||
init()
|
||||
|
||||
|
||||
def info(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.LIGHTCYAN_EX}[Info]{Fore.RESET} {text}{Fore.RESET}")
|
||||
|
||||
|
||||
def notice(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.LIGHTBLUE_EX}[Notice]{Fore.RESET} {text}{Fore.RESET}")
|
||||
|
||||
|
||||
def warn(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.YELLOW}[Warning] {text}{Fore.RESET}")
|
||||
|
||||
|
||||
def error(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.LIGHTRED_EX}[Error] {text}{Fore.RESET}")
|
||||
|
||||
|
||||
def debug(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.LIGHTMAGENTA_EX}[Debug] {text}{Fore.RESET}")
|
||||
|
||||
|
||||
def none(text):
|
||||
print(f"{Fore.LIGHTBLACK_EX}[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')}]"
|
||||
f"{Fore.RESET} {text}{Fore.RESET}")
|
|
@ -0,0 +1,8 @@
|
|||
[ 24.75] [INFO] Script started 11.12.2021 21:26:26.812422 UTC [root]
|
||||
[ 24.78] [WARNING] PyNaCl is not installed, voice will NOT be supported [discord.client]
|
||||
[ 24.78] [WARNING] Detected discord.Client! It is highly recommended to use `commands.Bot`. Do not add any `on_socket_response` event. [discord_slash]
|
||||
[ 24.95] [INFO] logging in using static token [discord.client]
|
||||
[ 25.48] [INFO] Shard ID None has sent the IDENTIFY payload. [discord.gateway]
|
||||
[ 25.68] [INFO] Shard ID None has connected to Gateway: ["gateway-prd-main-g9f5",{"micros":57772,"calls":["discord-sessions-green-prd-2-75",{"micros":56330,"calls":["start_session",{"micros":50451,"calls":["api-prd-main-63pc",{"micros":46236,"calls":["get_user",{"micros":4253},"add_authorized_ip",{"micros":1284},"get_guilds",{"micros":10131},"coros_wait",{"micros":1}]}]},"guilds_connect",{"micros":1,"calls":[]},"presence_connect",{"micros":191,"calls":[]}]}]}] (Session ID: 64da2f12e2bf37cd7d0e02cb9790f0fd). [discord.gateway]
|
||||
[ 27.71] [INFO] Syncing commands... [discord_slash]
|
||||
[ 46.21] [INFO] Logged in Discord as dan63047Bot#0924 [root]
|
|
@ -0,0 +1,228 @@
|
|||
import datetime
|
||||
import config
|
||||
import aprint
|
||||
import json
|
||||
import requests
|
||||
import random
|
||||
from urllib.request import urlopen
|
||||
|
||||
aprint.info("Script started")
|
||||
|
||||
try:
|
||||
fwords = json.loads(open("fword.json", "r").read())
|
||||
except:
|
||||
fwords = {"vk_fwords": {}, "ds_fwords": {}, "vk_last_fword": 0, "ds_last_fword": 0, "created": datetime.datetime.utcnow().timestamp()}
|
||||
|
||||
ds_delete_fword = requests.delete(f"https://discordapp.com/api/guilds/{config.DISCORD_GUILD}/members/{fwords['ds_last_fword']}/roles/{config.DISCORD_ROLE_fword}", headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'})
|
||||
if ds_delete_fword.ok:
|
||||
aprint.info(f"Discord remove role: {ds_delete_fword.status_code} {ds_delete_fword.reason}")
|
||||
else:
|
||||
aprint.error(f"Discord remove role: {ds_delete_fword.status_code} {ds_delete_fword.reason}")
|
||||
|
||||
midnight_text = ["Миднайт!",
|
||||
"Полночь!",
|
||||
"Midnight!",
|
||||
"миднигхт",
|
||||
"Середина ночи",
|
||||
"Смена даты!",
|
||||
"00:00",
|
||||
"Пора ложиться спать!",
|
||||
"12 ночи",
|
||||
"Медьникель!",
|
||||
"Мёднугхт!",
|
||||
"Ночное рандеву",
|
||||
"Опівночі!",
|
||||
"Арабская ночь",
|
||||
"Конец смены"]
|
||||
role_names = ["F-word дня",
|
||||
"Лох дня",
|
||||
"Приговорить к расстрелу",
|
||||
"Малолетний дебил",
|
||||
"Он отправится в Бразилию",
|
||||
"Пропустил много стрелок пока битбоксил с пикой точеной",
|
||||
"В дурку отправляется",
|
||||
"Поставил крейзифрог на рингтон",
|
||||
"Попросил наступить на себя еще раз",
|
||||
"ААХАААА ОН ДОЛБОЁБ ПОСМОТРИТЕ НА НЕГООО!!",
|
||||
"парннь ты долбоёб",
|
||||
"Быдло дня",
|
||||
"Фоткаю лучшего подписчика. Улыбнись",
|
||||
"Восхваляет солнце"]
|
||||
|
||||
imgvkrequest = requests.post("https://api.vk.com/method/photos.get", data={'owner_id': "-" + str(config.VK_GROUP_ID),
|
||||
'album_id': config.VK_ALBUM_MIDNIGHT_ID,
|
||||
'count': 1000,
|
||||
'access_token': config.VK_SERVICE_TOKEN,
|
||||
'v': '5.124'})
|
||||
if imgvkrequest.ok:
|
||||
try:
|
||||
random_images_query = json.loads(imgvkrequest.text)
|
||||
random_number = random.randint(0, random_images_query['response']['count']-1)
|
||||
aprint.info(f"VK method 'photos.get': {imgvkrequest.status_code} {imgvkrequest.reason}, returned photos: {random_images_query['response']['count']}, selected: {random_number}")
|
||||
image = random_images_query['response']['items'][random_number]
|
||||
image_request = urlopen(image["sizes"][-1]['url']).read()
|
||||
image_file = open("md.jpg", "wb")
|
||||
image_file.write(image_request)
|
||||
image_file.close()
|
||||
MIDNIGHT_IMAGE = True
|
||||
except Exception as e:
|
||||
MIDNIGHT_IMAGE = False
|
||||
aprint.error(f"Error while getting image: {str(e)}")
|
||||
else:
|
||||
MIDNIGHT_IMAGE = False
|
||||
aprint.error(f"VK method 'photos.get': {imgvkrequest.status_code} {imgvkrequest.reason}")
|
||||
selected = random.choice(midnight_text)
|
||||
now = datetime.datetime.utcnow()
|
||||
new_date = now + datetime.timedelta(hours=3, minutes=3)
|
||||
to_ny = datetime.datetime(year=2022, month=1, day=1) - now
|
||||
if 30 >= to_ny.days > 1:
|
||||
if MIDNIGHT_IMAGE:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nДо нового года осталось {to_ny.days} дн.\nКартинка дня:"
|
||||
else:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nДо нового года осталось {to_ny.days} дн.\nОшибка при получении картинки дня"
|
||||
elif to_ny.days == 1:
|
||||
if MIDNIGHT_IMAGE:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nДо нового года осталось 24 часа.\nКартинка дня:"
|
||||
else:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nДо нового года осталось 24 часа.\nОшибка при получении картинки дня"
|
||||
elif to_ny.days == 0:
|
||||
if MIDNIGHT_IMAGE:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nC новым, 2022 годом!!!\nКартинка дня:"
|
||||
else:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nC новым, 2022 годом!!!\nОшибка при получении картинки дня"
|
||||
else:
|
||||
if MIDNIGHT_IMAGE:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\nКартинка дня:"
|
||||
else:
|
||||
text = f"{selected}\nНаступило {new_date.strftime('%d.%m.%Y')}\n\nОшибка при получении картинки дня"
|
||||
aprint.info(f"All ready. Waiting...")
|
||||
|
||||
MIDNIGHT = False
|
||||
while not MIDNIGHT:
|
||||
now = datetime.datetime.utcnow()
|
||||
if now.hour == 21 and now.minute == 0 and now.second == 1:
|
||||
aprint.info("Midnight")
|
||||
if MIDNIGHT_IMAGE:
|
||||
dcrequest = requests.post(f"https://discordapp.com/api/channels/{config.DISCORD_CHANNEL_ID}/messages",
|
||||
headers={'Authorization': f'Bot {config.DISCORD_TOKEN}',
|
||||
'Content-Disposition': 'form-data; filename="md.jpg"'},
|
||||
data={'payload_json': json.dumps({'content': text}), },
|
||||
files={'file': open("md.jpg", 'rb')})
|
||||
vkrequest = requests.post("https://api.vk.com/method/messages.send",
|
||||
data={'peer_id': int(config.VK_DIALOG_ID), 'message': text,
|
||||
'random_id': random.randint(-9223372036854775808, 9223372036854775807),
|
||||
'attachment': f"photo{image['owner_id']}_{image['id']}",
|
||||
'access_token': config.VK_TOKEN, 'v': '5.124'})
|
||||
else:
|
||||
dcrequest = requests.post(f"https://discordapp.com/api/channels/{config.DISCORD_CHANNEL_ID}/messages",
|
||||
headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'},
|
||||
data={'payload_json': json.dumps({'content': text}), })
|
||||
vkrequest = requests.post("https://api.vk.com/method/messages.send",
|
||||
data={'peer_id': int(config.VK_DIALOG_ID), 'message': text,
|
||||
'random_id': random.randint(-9223372036854775808, 9223372036854775807),
|
||||
'access_token': config.VK_TOKEN, 'v': '5.124'})
|
||||
if dcrequest.ok:
|
||||
aprint.info(f"Message to Discord: {dcrequest.status_code} {dcrequest.reason}")
|
||||
else:
|
||||
aprint.error(f"Message to Discord: {dcrequest.status_code} {dcrequest.reason}")
|
||||
if vkrequest.ok:
|
||||
aprint.info(f"Message to VK: {vkrequest.status_code} {vkrequest.reason}")
|
||||
else:
|
||||
aprint.error(f"Message to VK: {vkrequest.status_code} {vkrequest.reason}")
|
||||
vk_users_request = requests.post("https://api.vk.com/method/messages.getConversationMembers",
|
||||
data={'peer_id': config.VK_DIALOG_ID, 'fields': config.VK_ALBUM_MIDNIGHT_ID,
|
||||
'group_id': config.VK_GROUP_ID, 'access_token': config.VK_TOKEN,
|
||||
'v': '5.124'})
|
||||
if vk_users_request.ok:
|
||||
aprint.info(f"VK method 'messages.getConversationMembers': {vk_users_request.status_code} {vk_users_request.reason}")
|
||||
random_members_query = json.loads(vk_users_request.text)
|
||||
if not fwords.get('vk_fword_story_3'):
|
||||
fwords['vk_fword_story_3'] = 0
|
||||
if not fwords.get('vk_fword_story_2'):
|
||||
fwords['vk_fword_story_2'] = 0
|
||||
if not fwords.get('vk_fword_story_1'):
|
||||
fwords['vk_fword_story_1'] = 0
|
||||
new_vk_fword = False
|
||||
while not new_vk_fword:
|
||||
random_member = random.choice(random_members_query['response']['profiles'])
|
||||
black_list = [292394871, 32272927]
|
||||
white_list = [260168666]
|
||||
debug_text = f"VK random person: {random_member['first_name']} {random_member['last_name']} - "
|
||||
if (random_member['id'] != fwords['vk_last_fword'] and random_member['id'] != fwords['vk_fword_story_1'] and random_member['id'] != fwords['vk_fword_story_2'] and random_member['id'] != fwords['vk_fword_story_3'] and random_member['id'] not in white_list) or random_member['id'] in black_list:
|
||||
aprint.debug(debug_text + "selected")
|
||||
fwords['vk_fword_story_3'] = fwords['vk_fword_story_2']
|
||||
fwords['vk_fword_story_2'] = fwords['vk_fword_story_1']
|
||||
fwords['vk_fword_story_1'] = fwords['vk_last_fword']
|
||||
fwords['vk_last_fword'] = random_member['id']
|
||||
if str(random_member['id']) in fwords["vk_fwords"]:
|
||||
fwords["vk_fwords"][str(random_member['id'])] += 1
|
||||
else:
|
||||
fwords["vk_fwords"][str(random_member['id'])] = 1
|
||||
text = f"{random.choice(role_names)}: @id{random_member['id']} ({random_member['first_name']} {random_member['last_name']})"
|
||||
vkrequest = requests.post("https://api.vk.com/method/messages.send",
|
||||
data={'peer_id': config.VK_DIALOG_ID, 'message': text,
|
||||
'random_id': random.randint(-9223372036854775808, 9223372036854775807),
|
||||
'access_token': config.VK_TOKEN, 'v': '5.124'})
|
||||
new_vk_fword = True
|
||||
if vkrequest.ok:
|
||||
aprint.info(f"Message to VK: {vkrequest.status_code} {vkrequest.reason}")
|
||||
else:
|
||||
aprint.error(f"Message to VK: {vkrequest.status_code} {vkrequest.reason}")
|
||||
else:
|
||||
aprint.debug(debug_text + "not selected")
|
||||
else:
|
||||
aprint.error(f"VK method 'messages.getConversationMembers': {vk_users_request.status_code} {vk_users_request.reason}")
|
||||
ds_members_r = requests.get(f"https://discordapp.com/api/guilds/{config.DISCORD_GUILD}/members?limit=1000",
|
||||
headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'})
|
||||
if ds_members_r.ok:
|
||||
aprint.info(f"Discord guild member list request: {ds_members_r.status_code} {ds_members_r.reason}")
|
||||
ds_members = json.loads(ds_members_r.text)
|
||||
if not fwords.get('ds_fword_story_3'):
|
||||
fwords['ds_fword_story_3'] = 0
|
||||
if not fwords.get('ds_fword_story_2'):
|
||||
fwords['ds_fword_story_2'] = 0
|
||||
if not fwords.get('ds_fword_story_1'):
|
||||
fwords['ds_fword_story_1'] = 0
|
||||
new_ds_fword = False
|
||||
black_list = [235010902640820225, 611931400094089269]
|
||||
white_list = [324555734115418112]
|
||||
while not new_ds_fword:
|
||||
member_fword = random.choice(ds_members)
|
||||
debug_text = f"DS random person: {member_fword['user']['username']}#{member_fword['user']['discriminator']} - "
|
||||
if (member_fword['user']['id'] != fwords['ds_last_fword'] and member_fword['user']['id'] != fwords['ds_fword_story_1'] and member_fword['user']['id'] != fwords['ds_fword_story_2'] and member_fword['user']['id'] != fwords['ds_fword_story_3'] and member_fword['user']['id'] not in white_list) or member_fword['user']['id'] in black_list:
|
||||
aprint.debug(debug_text + "selected")
|
||||
fwords['ds_fword_story_3'] = fwords['ds_fword_story_2']
|
||||
fwords['ds_fword_story_2'] = fwords['ds_fword_story_1']
|
||||
fwords['ds_fword_story_1'] = fwords["ds_last_fword"]
|
||||
fwords["ds_last_fword"] = member_fword['user']['id']
|
||||
new_ds_fword = True
|
||||
random_role = random.choice(role_names)
|
||||
ds_req_rename_role = requests.patch(f"https://discordapp.com/api/guilds/{config.DISCORD_GUILD}/roles/{config.DISCORD_ROLE_fword}", headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'}, json={'name': random_role, 'color':random.randint(0x000000, 0xffffff)})
|
||||
if ds_req_rename_role.ok:
|
||||
aprint.info(f"Discord rename role: {ds_req_rename_role.status_code} {ds_req_rename_role.reason}")
|
||||
else:
|
||||
aprint.error(f"Discord rename role: {ds_req_rename_role.status_code} {ds_req_rename_role.reason}")
|
||||
text = f"{random_role}: <@{member_fword['user']['id']}>"
|
||||
ds_send_message_r = requests.post(f"https://discordapp.com/api/channels/{config.DISCORD_CHANNEL_ID}/messages", headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'}, data={'payload_json': json.dumps({'content': text})})
|
||||
if ds_send_message_r.ok:
|
||||
aprint.info(f"Message to Discord: {dcrequest.status_code} {dcrequest.reason}")
|
||||
else:
|
||||
aprint.error(f"Message to Discord: {dcrequest.status_code} {dcrequest.reason}")
|
||||
ds_set_fword = requests.put(f"https://discordapp.com/api/guilds/{config.DISCORD_GUILD}/members/{member_fword['user']['id']}/roles/{config.DISCORD_ROLE_fword}", headers={'Authorization': f'Bot {config.DISCORD_TOKEN}'})
|
||||
if ds_set_fword.ok:
|
||||
aprint.info(f"Discord set role: {ds_set_fword.status_code} {ds_set_fword.reason}")
|
||||
else:
|
||||
aprint.error(f"Discord set role: {ds_set_fword.status_code} {ds_set_fword.reason}")
|
||||
if str(member_fword['user']['id']) in fwords['ds_fwords']:
|
||||
fwords['ds_fwords'][str(member_fword['user']['id'])] += 1
|
||||
else:
|
||||
fwords['ds_fwords'][str(member_fword['user']['id'])] = 1
|
||||
else:
|
||||
aprint.debug(debug_text + "not selected")
|
||||
else:
|
||||
aprint.error(f"Discord guild member list request: {ds_members_r.status_code} {ds_members_r.reason}")
|
||||
with open("fword.json", "w") as jsn:
|
||||
json.dump(fwords, jsn)
|
||||
MIDNIGHT = True
|
||||
|
||||
aprint.info("Done")
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
Loading…
Reference in New Issue