Skip to content

Instantly share code, notes, and snippets.

@bwikbs
Created February 11, 2021 20:26
Show Gist options
  • Save bwikbs/750eff939389ad826de3698d2db89df3 to your computer and use it in GitHub Desktop.
Save bwikbs/750eff939389ad826de3698d2db89df3 to your computer and use it in GitHub Desktop.
몽사마의눈 소스
import asyncio
import discord
import a2s
client = discord.Client()
token = "discord bot token"
servers = [
["114.207.167.252", 47332],
["114.207.167.252", 47334],
["114.207.167.252", 47348],
["114.207.167.252", 47330],
["114.207.167.252", 47452],
["114.207.167.252", 47354],
["114.207.167.252", 47356],
["114.207.167.252", 47358],
["114.207.167.252", 47344],
["114.207.167.252", 47338],
["114.207.167.252", 47346],
["114.207.167.252", 47342],
# ["114.207.167.252", 47330],
]
def dump_server(ip,port):
result=""
total = 0
address = (ip, port)
result+=a2s.info(address).server_name + "\n"
for player in a2s.players(address):
if player.name:
total=total+1
result+="인원수:"+str(total)+ "\n"
result+="---------------------------------------------------------\n"
return result
def dump_server2(ip,port):
result="-----------------------start-----------------------------\n"
total = 0
try:
address = (ip, port)
result+="서버 이름:"+a2s.info(address).server_name + "\n"
# result+="player_count:"+str(a2s.info(address).player_count)+ "\n"
# result+="player_count:"+str(len(a2s.players(address)))+ "\n"
for player in a2s.players(address):
if player.name:
total=total+1
result+="player name:"+player.name+"\n"
# a2s.rules(address)
result+="player_count:"+str(total)+ "\n"
# for player in a2s.players(address):
#result+="player name:"+player.name
# a2s.rules(address)
except:
result+="서버에 문제가 있습니다........ \n"
result+="--------------------------end----------------------------\n"
return result
@client.event
async def on_ready():
print("Logged in as ") #화면에 봇의 아이디, 닉네임이 출력됩니다.
print(client.user.name)
print(client.user.id)
print("===========")
# 디스코드에는 현재 본인이 어떤 게임을 플레이하는지 보여주는 기능이 있습니다.
# 이 기능을 사용하여 봇의 상태를 간단하게 출력해줄 수 있습니다.
await client.change_presence(game=discord.Game(name="반갑습니다 :D", type=1))
# 봇이 새로운 메시지를 수신했을때 동작되는 코드입니다.
@client.event
async def on_message(message):
if message.author.bot: #만약 메시지를 보낸사람이 봇일 경우에는
return None #동작하지 않고 무시합니다.
id = message.author.id #id라는 변수에는 메시지를 보낸사람의 ID를 담습니다.
channel = message.channel #channel이라는 변수에는 메시지를 받은 채널의 ID를 담습니다.
if message.content.startswith('!c'):
newMsg = "Corey\n"
print(newMsg)
await message.channel.send(newMsg)
for (ip, port) in servers:
newMsg =dump_server2(ip, port)
print(newMsg)
await message.channel.send(newMsg)
# elif message.content.startswith('!c ak'):
# newMsg = "AllKill\n"
# elif message.content.startswith('!c uia'):
# newMsg = "UIA\n"
#else: #위의 if에 해당되지 않는 경우
#메시지를 보낸사람을 호출하며 말한 메시지 내용을 그대로 출력해줍니다.
# print(message.content)
# await message.channel.send("<@"+str(id)+">님이 \""+message.content+"\"라고 말하였습니다.")
client.run(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment