Refactor Cleanup Telegramm Code -> Wurde gekapselt in osiris_listener_telegramm

main
Alex 5 months ago
parent 4a4e6700c7
commit 445d3fe9a0

@ -27,70 +27,30 @@ java_minecraft_servers = {
"mc_vanilla" : {
'profile_id': 'vanilla',
'server_name': 'Vanilla 1.21',
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/Vanilla_1-21/',
'command': ['C:/Program Files/Java/jdk-22/bin/java.exe', '-Xmx1024M', '-Xms1024M', '-jar', 'minecraft_server.1.21.jar', '--nogui', '--bonusChest'],
'wait_time': 30
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/Vanilla_1-21/'
},
"mc_sanderpack" : {
'profile_id': 'sanderpack',
'server_name': 'The 1.12.2 Pack (SanderPack)',
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/1-12-2-Pack/',
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx16G', '-XX:+UseG1GC','-Xms4G', '-Dsun.rmi.dgc.server.gcInterval=2147483646', '-XX:+UnlockExperimentalVMOptions', '-XX:G1NewSizePercent=20', '-XX:G1ReservePercent=20', '-XX:MaxGCPauseMillis=50', '-XX:G1HeapRegionSize=32M', '-Dfml.queryResult=confirm', '-Duser.language=en', '-jar', 'forge-1.12.2-14.23.5.2860.jar', '--nogui', '--bonusChest'],
'wait_time': 30
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/1-12-2-Pack/'
},
"mc_sanderhorizons" : {
'profile_id': 'sanderhorizons',
'server_name': 'GT New Horizons 2.6.0 (SanderHorizons)',
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/gt_new_horizons_2.6.0/',
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx12G', '-Xms4G', '-XX:+UseStringDeduplication', '-XX:+UseCompressedOops', '-XX:+UseCodeCacheFlushing', '-Dfml.readTimeout=180', '-jar', 'forge-1.7.10-10.13.4.1614-1.7.10-universal.jar', '--nogui', '--bonusChest'],
'wait_time': 30
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/gt_new_horizons_2.6.0/'
},
"mc_sanderhardcore" : {
'profile_id': 'sanderhardcore',
'server_name': 'RLCraft 2.9.3 (SanderHardcore)',
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/rlcraft/',
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx16G', '-Xms4G', '-jar', 'forge-1.12.2-14.23.5.2860.jar', '--nogui', '--bonusChest'],
'wait_time': 30
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/rlcraft/'
},
"mc_sandervalley" : {
'profile_id': 'sandervalley',
'server_name': 'Farming Valley (SanderValley)',
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/farming_valley_1-1-2/',
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Dlog4j2.formatMsgNoLookups=true', '-Dlog4j.configurationFile=log4j2.xml', '-Xmx8G', '-Xms2G', '-jar', 'forge-1.10.2-12.18.3.2511-universal.jar', '--nogui', '--bonusChest'],
'wait_time': 30
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/farming_valley_1-1-2/'
}
}
####
# Telegramm Functions
####
# Telegram bot token
TELEGRAM_BOT_TOKEN = '6984289827:AAHNUM4F_U6233oa75nX5jXyQY6vC0NlZvw'
# Create an Bot with a larger connection pool and longer pool timeout
bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
# File to store subscriber chat IDs
SUBSCRIBERS_FILE = 'telegramm_subscribers.txt'
def load_subscribers():
"""Load subscriber chat IDs from the file."""
if os.path.exists(SUBSCRIBERS_FILE):
with open(SUBSCRIBERS_FILE, 'r') as file:
return [line.strip() for line in file.readlines()]
return []
async def send_telegram_message(message):
"""Send a message to all subscribers."""
subscribers = load_subscribers()
for chat_id in subscribers:
try:
prepped_message = f"{message}"
await bot.send_message(chat_id=chat_id, text=prepped_message)
except telegram.error.TelegramError as e:
logging.error(f"Error sending message to {chat_id}: {e}")
####
# Tool Functions
####

Loading…
Cancel
Save